在T-SQL中,when
关键字是什么?
when
注意::我尝试在网络上进行搜索(例如,“ Google搜索”),但是由于“时间”一词无处不在,因此我找不到合适的解释。
此外,SQL关键字列表不包含“ when”,因此该列表不是穷举性的,或者对于T-SQL而言是唯一的(或者可能是在某些“较新”的T-SQL / SSMS版本中添加的) 。链接到此特定的SQL关键字站点: https://www.w3schools.com/sql/sql_ref_keywords.asp
答案 0 :(得分:3)
它与CASE关键字结合使用,它本质上就像是一个switch或'if'语句……例如:
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]
答案 1 :(得分:1)
WHEN
也是MERGE语句的一部分:
根据与源表的联接结果在目标表上运行插入,更新或删除操作
MERGE [ INTO ] <target_table> [ WITH ( <merge_hint> ) ] [ [ AS ] table_alias ] USING <table_source> ON <merge_search_condition> [ WHEN MATCHED [ AND <clause_search_condition> ] THEN <merge_matched> ] [ ...n ] [ WHEN NOT MATCHED [ BY TARGET ] [ AND <clause_search_condition> ] THEN <merge_not_matched> ] [ WHEN NOT MATCHED BY SOURCE [ AND <clause_search_condition> ] THEN <merge_matched> ] [ ...n ] ;