本文介绍了然后sql语句其他条件返回null值的情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨专家, 这是我的sql querry declare @ lastPensionMonth varchar ( 50 ) 选择 top 1 @ lastPensionMonth = 案例 何时 BMT_MONTH = ' 1' 然后 ' jan' 何时 BMT_MONTH = ' 2' 然后 ' feb' 当 BMT_MONTH = ' 3' 然后 ' mar' 当 BMT_MONTH = ' 4' ' apr' 何时 BMT_MONTH = ' 5' 然后 ' 可能' when BMT_MONTH = ' 6' 吨母鸡 ' jun' 当 BMT_MONTH = ' 7' 然后 ' jul' 何时 BMT_MONTH = ' 8' 然后 ' aug' BMT_MONTH = ' 9' 然后 ' spt' 何时 BMT_MONTH = ' 10' 然后 ' oct' 何时 BMT_MONTH = ' 11' 然后 ' nov' 何时 BMT_MONTH = ' 12' 然后 ' dec' else ' 未开始领取养老金' 结束 来自 Beneficiary_Monthly_Pension_Tran 其中 BMT_Beneficiary_ID = ' 000002316' order by bmt_year desc select @ lastPensionMonth 它没有返回else条件字符串它正常工作的真实部分 false部分它返回null值。任何人都可以告诉我错误。 提前致谢 (Keerthi Kumar)解决方案 删除 else 未开始领取养老金 add 声明 @ lastPensionMonth varchar ( 50 ) SET @ lastPensionMonth = ' 未开始领养养老金 是的问题是没有开始领取养老金 使用'未开始领取养老金' Hi experts,Here is my sql querrydeclare @lastPensionMonth varchar(50)Select top 1 @lastPensionMonth = case when BMT_MONTH= '1' then 'jan' when BMT_MONTH= '2' then 'feb' when BMT_MONTH= '3' then 'mar' when BMT_MONTH= '4' then 'apr' when BMT_MONTH= '5' then 'may' when BMT_MONTH= '6' then 'jun' when BMT_MONTH= '7' then 'jul' when BMT_MONTH= '8' then 'aug' when BMT_MONTH= '9' then 'spt' when BMT_MONTH= '10' then 'oct' when BMT_MONTH= '11' then 'nov' when BMT_MONTH= '12' then 'dec' else 'Not started to take pension' end from Beneficiary_Monthly_Pension_Tran where BMT_Beneficiary_ID='000002316' order by bmt_year desc select @lastPensionMonthIt is not returning the else condition string for the true part it is working properlyfalse part it is returning null value. Can Any one please tell me the mistake.Thanks in advance(Keerthi Kumar) 解决方案 Remove else "Not started to take pension"adddeclare @lastPensionMonth varchar(50)SET @lastPensionMonth='Not started to take pension'yes the issue is "Not started to take pension"use 'Not started to take pension' 这篇关于然后sql语句其他条件返回null值的情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 01:26