sql server中类似oracle中decode功能的函数

时间:2022-10-03 18:32:18

sqlserver 2008 写法

select t.PROJECTNAME,
t.BUILDCONTENTSCALE,
CASE t.PROJECTLEVEL
WHEN '' THEN '国家重点'
WHEN '' THEN '省重点'
WHEN '' THEN '市重点'
WHEN '' THEN '区/县重点'
END AS PROJECTLEVEL,
t.TOTALINVESTMENT,
t.PROGRESSCONTENT,
t.BUILDCOMPANY,
t.CONTACTWAY,
t.DUTYDEPT,
t.REMARK
from t_iipms_applayprojects t
where t.projecttype = ''
and t.isvoided = '';

oracle中的写法

select t.PROJECTNAME,
t.BUILDCONTENTSCALE,
decode(t.PROJECTLEVEL,
'',
'国家重点',
'',
'省重点',
'',
'市重点',
'',
'区/县重点') as PROJECTLEVEL,
t.TOTALINVESTMENT,
t.PROGRESSCONTENT,
t.BUILDCOMPANY,
t.CONTACTWAY,
t.DUTYDEPT,
t.REMARK
from t_iipms_applayprojects t
where t.projecttype = ''
and t.isvoided = '';

细节对比看效果很明显:SQL Server 2008中

CASE t.PROJECTLEVEL
WHEN '' THEN '国家重点'
WHEN '' THEN '省重点'
WHEN '' THEN '市重点'
WHEN '' THEN '区/县重点'
END AS PROJECTLEVEL

Oracle 10g中

decode(t.PROJECTLEVEL,
'',
'国家重点',
'',
'省重点',
'',
'市重点',
'',
'区/县重点') as PROJECTLEVEL

原文地址:

https://blog.csdn.net/hu_shengyang/article/details/10533865