我想将这些条件放在我的存储过程中
if ((select PriSubmissionStatusId from Claim where ClaimId = 375 )!= 106 ) Print 'Primary'
else if((select SecSubmissionStatusId from Claim where ClaimId = 375 )= 0)print 'Primary'
else if((select SecSubmissionStatusId from Claim where ClaimId = 375 )!= 106)print 'Secoundary'
else if((select OthSubmissionStatusId from Claim where ClaimId = 375 )= 0)print 'Secoundry'
else if((select OthSubmissionStatusId from Claim where ClaimId = 375 )!= 106)print 'Other'
else print 'Primary'
作为列名构建,它们也是来自不同表的存储过程中的其他列。任何想法?
答案 0 :(得分:0)
使用Case When
代替if else
SELECT CASE WHEN PriSubmissionStatusId <> 106 THEN 'Primary'
WHEN SecSubmissionStatusId = 0 THEN 'Primary'
WHEN SecSubmissionStatusId <> 106 THEN 'Secoundary'
WHEN OthSubmissionStatusId = 0 THEN 'Secoundry'
WHEN OthSubmissionStatusId <> 106 THEN 'Other'
END
FROM Claim
WHERE ClaimId = 375