MS SQL的CASE...WHEN...THEN...END语法

根据多个可能的答案检查一个值或变量。

举例说明:

 

SELECT [type],CASE [type] 
              WHEN 'TT' THEN 'TYPE_TABLE'
              WHEN 'FN' THEN 'SQL_SCALAR_FUNCTION'
              WHEN 'C' THEN 'CHECK_CONSTRAINT'
              WHEN 'SQ' THEN 'SERVICE_QUEUE' 
              WHEN 'F' THEN 'FOREIGN_KEY_CONSTRAINT' 
              WHEN 'U' THEN 'USER_TABLE' 
              WHEN 'D' THEN 'DEFAULT_CONSTRAINT' 
              WHEN 'PK' THEN 'PRIMARY_KEY_CONSTRAINT'
              WHEN 'S' THEN 'SYSTEM_TABLE' 
              WHEN 'IT' THEN 'INTERNAL_TABLE' 
              WHEN 'P' THEN 'SQL_STORED_PROCEDURE' 
              WHEN 'TF' THEN 'SQL_TABLE_VALUED_FUNCTION' 
              WHEN 'TR' THEN 'SQL_TRIGGER' 
              END AS [type description]
FROM (
    SELECT DISTINCT [type] FROM sys.objects
) O
    
Source Code

 

posted @ 2019-05-20 14:11  Insus.NET  阅读(640)  评论(0编辑  收藏  举报