在sqlserver的条件分支case when有两种写法:
1)case 字段 when 值 then 返回值 when 值2 then 返回值2 end
2)case when 条件1 then 返回值1 when 条件2 then 返回值2 end
方法步骤:
1.打开“SQL Server Management Studio”管理工具,创建一张测试表:
CREATE TABLE tblCaseWhen(
Id varchar(40) NOT NULL,
Col1 varchar(50) NULL,
Col2 int NULL,
Col3 varchar(50) NULL,
Col4 varchar(50) NULL
)
2.往测试表中插入测试数据:
inse