首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用case语句检查列是否为空

如何使用case语句检查列是否为空
EN

Stack Overflow用户
提问于 2013-10-01 08:03:20
回答 1查看 4.3K关注 0票数 0

我必须使用3个表创建一个存储过程,第一个是登记表、求职者表、就业明细表。因为我现在在前两个tables.Till中有条目,所以在就业明细表中没有任何条目。

我有以下问题:

代码语言:javascript
运行
复制
select RD.FirstName,RD.LastName,
(select case when JR.profileHeadline=''
then 'No Resume Headline mentioned' 
else JR.profileHeadline end
from jobseekerReg JR)as profileHeadline ,
(select case when ED.designation=''
then 'No designation mentioned'
else ED.designation end
from employmentDetail ED)as designation,
(select case when ED.companyName=''
then 'No company name mentioned'
else ED.companyName end
from employmentDetail ED) as companyName,JR.location,
(select case when ED.funcArea=''
then 'No functional area mentioned'
else ED.funcArea end
from employmentDetail ED) as funcArea ,
(select case when ED.cmpIndustry=''
then 'No industry mentioned'
else ED.cmpIndustry end
from employmentDetail ED)as cmpIndustry,RD.BirthDay,
RD.Gender,JR.experience,
(select case when ED.salary=''
then 'No salary mentioned'
else ED.salary end
from employmentDetail ED)as salary ,JR.mobileNumber,JR.emailId,
JR.altEmailID,JR.jobSeekerAddrs,JR.maritalStatus,
(select case when JR.keySkills=''
then 'No keyskills mentioned'
else JR.keySkills end
from jobseekerReg JR)as keySkills
from RegistrationDetails RD join jobseekerReg JR on RD.Reg_Id=JR.regId
left outer join employmentDetail ED on ED.regId=JR.regId 
and ED.regId=2  where RD.Reg_Id=JR.regId and RD.Reg_Id=2 and JR.regId=2

上面的查询提供了正确的输出,但问题是,由于regId=2的就业表中没有任何条目,因此该表中的列将输出作为null。我该如何处理这个问题?请提前给我任何解决方案谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-01 08:18:49

代码语言:javascript
运行
复制
CASE WHEN ED.Salary IS NULL THEN 'No salary mentioned' ELSE ED.Salary END

但我认为就你的情况而言,ISNULL()会更好:

代码语言:javascript
运行
复制
select RD.FirstName,RD.LastName,
ISNULL(JR.profileHeadline, 'No Resume Headline mentioned') as profileHeadline ,
ISNULL(ED.designation, 'No designation mentioned') as designation,
ISNULL(ED.companyName, 'No company name mentioned')  as companyName, 
JR.location,
ISNULL(ED.funcArea, 'No functional area mentioned') as funcArea ,
ISNULL(ED.cmpIndustry, 'No industry mentioned') as cmpIndustry,
RD.BirthDay,
RD.Gender, JR.experience,
ISNULL(ED.salary, 'No salary mentioned' as salary ,
JR.mobileNumber,JR.emailId,
JR.altEmailID,JR.jobSeekerAddrs,JR.maritalStatus,
ISNULL(JR.keySkills, 'No keyskills mentioned') as keySkills
from RegistrationDetails RD join jobseekerReg JR on RD.Reg_Id=JR.regId
left outer join employmentDetail ED on ED.regId=JR.regId 
and ED.regId=2  where RD.Reg_Id=JR.regId and RD.Reg_Id=2 and JR.regId=2
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19110982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档