2013-10-01 129 views
0

我必须使用3个表创建存储过程,第一个是注册表,求职者表,求职明细表。 因为我在前两个表中有条目。现在我没有在任何细节表中输入任何内容。如何使用case语句来检查列是否为空

我有以下查询:

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的就业表中,该表中的列给出了输出为空。 我应该如何处理这个问题? 建议我任何解决方案 在此先感谢。

+0

使用'ISNULL(字段名,“默认值”)'来设置默认数据为空字段,如果这是你想要的。否则,使用值填充字段可能会出现问题。 – Nisha

回答

1
CASE WHEN ED.Salary IS NULL THEN 'No salary mentioned' ELSE ED.Salary END 

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

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 
+0

上述查询对于来自就业细节的字段工作正常。并且它没有在来自注册表和求职者表 –

+0

@AshwiniAgivalem的字段中给出任何值,您应该在数据中查找问题。我有回答您的原始问题吗? –

相关问题