PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 9, 2022

[FIXED] What is the 'when keyword' used for in T-SQL?

 July 09, 2022     keyword, sql-server, tsql     No comments   

Issue

What is the when keyword used for in T-SQL?

when

NOTE: I tried searching this on the web (e.g. 'Googling')... however due to the ubiquitous nature of the word 'when', I wasn't able to find a good explanation.

Furthermore, a list of SQL keywords did not include 'when' so either the list was not exhaustive or it is unique to T-SQL (or perhaps it was added in some 'newer' version of T-SQL / SSMS). Link to this particular SQL keyword site: https://www.w3schools.com/sql/sql_ref_keywords.asp


Solution

It's used in conjunction with the CASE keyword, which is like a switch, or 'if' statement essentially... for example:

SELECT 
    CASE WHEN [Column] = 1 THEN 'Column is 1'
         WHEN [Column] = 2 THEN 'Column is 2'
         ELSE 'Column is not 1 or 2'
         END AS [Description]


Answered By - Milney
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing