【发布时间】:2018-12-20 14:09:44
【问题描述】:
如何更改由以下 case 语句生成的参数值:
Set @CostType=Case When @ShowLabor ='Y'and @ShowEquipment ='Y' then ('1,3,5,7,8')
when @ShowLabor ='Y'and @ShowEquipment ='N' then ('3,5')
when @ShowLabor ='N'and @ShowEquipment ='Y' then ('1,7,8')
else ('1,3,5,7,8') end
到整数列表 [EX:(1,3,5,7,8)] 以成为此 IN 语句的一部分:
Where JCCD.CostType in (@CostType)
我也尝试将其作为临时表中的一列,如下所示,让我知道这是否更容易转换:
Declare @TempTable table (CostType int)
Set NOCOUNT ON;
Insert into @TempTable values
(Case When @ShowLabor ='Y'and @ShowEquipment ='Y' then ('1,3,5,7,8')
when @ShowLabor ='Y'and @ShowEquipment ='N' then ('3,5')
when @ShowLabor ='N'and @ShowEquipment ='Y' then ('1,7,8')
else ('1,3,5,7,8') end )
【问题讨论】:
标签: sql string casting integer