2013-10-01 76 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的字段中給出任何值,您應該在數據中查找問題。我有回答您的原始問題嗎? –