如何使用sql server 2008中的case语句将null和blank替换为某个值 [英] How to replace null and blank with some value using case statement in sql server 2008
本文介绍了如何使用sql server 2008中的case语句将null和blank替换为某个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的表中,我希望在EmpName列中找到空值时显示我为空,并且当在EmpName列中找到空值时,我是空白,因为表是设计的,怎么办,请告诉我
In my table I want to display I am null when null value found in EmpName column and I am blank when blank value found in EmpName column, as table is designed, how to do this, please let me know
Create table #temp
(
EmpID int,
EmpName nvarchar(50)
)
-----------------------------------------
Insert into #temp Values(1,'Ram')
Insert into #temp Values(2,'')
Insert into #temp Values(3,Null)
Insert into #temp Values(4,'Shyam')
Insert into #temp Values(5,'')
Insert into #temp Values(5,Null)
-----------------------------------------
Select *, EmpName1=(CASE EmpName
WHEN NULL THEN 'I am Null'
WHEN '' THEN 'I am Blank'
ELSE EmpName
END) from #temp
-----------------------------------------
推荐答案
C哎呀...
Hi,
Check this...
Select *, EmpName1=
CASE WHEN EmpName IS NULL THEN 'I am NULL'
WHEN EmpName='' THEN 'I am Blank'
ELSE EmpName
END
from #temp
希望这会对你有所帮助。
干杯
Hope this will help you.
Cheers
这篇关于如何使用sql server 2008中的case语句将null和blank替换为某个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文