【发布时间】:2018-10-31 10:02:45
【问题描述】:
我的数据库 tblCustomer 中有一个表,它有 8 个布尔字段(MS01、MS02...MS08) 使用 SSRS 报告,我有一个多值参数下拉列表,允许选择 10 个值中的每一个 因此,如果我从列表中选择 MS01 和 MS05,参数 @idSite 将等于 'MS01','MS05'
'-1' = 真
我想从 tblCustomer 中选择所选参数值为 true 的所有记录
select idCustomer, MS01, MS02,MS03, MS04,MS05,MS06,MS07,MS08 from tblCustomer
WHERE (tblCustomer.CustomerYN = '-1')
AND
CASE
WHEN @idSite like '%MS01%' THEN tblCustomer.MS01=-1
WHEN @idSite like '%MS02%' THEN tblCustomer.MS02=-1
WHEN @idSite like '%MS03%' THEN tblCustomer.MS03=-1
END as MailShot
当字符串在参数中时,我也尝试过使用
select idCustomer, MS01, MS02,MS03, MS04,MS05,MS06,MS07,MS08 from
tblCustomer
WHERE (tblCustomer.CustomerYN = '-1')
AND
CASE
WHEN 'MS01' in @idSite THEN tblCustomer.MS01=-1
WHEN 'MS02' in @idSite THEN tblCustomer.MS02=-1
END as MailShot
我以为我很接近上面的内容,但没有快乐。谁能指出我正确的方向?
编辑
@idSite 是 SSRS 多值参数下拉列表。 它根据下拉列表中的部分从下表中获取值 idMailshot
idMailShot Location
MS01 Location1
MS02 Location2
MS03 Location3
MS04 Location4
MS05 Location5
MS06 Location6
MS07 Location7
MS08 Location8
MS09 Location9
所以如果我从下拉列表中选择位置 1 和位置 2,“MS01,MS02”应该作为@idSite 传递 我想要
select idCustomer from tblCustomer where
tblCustomer.MS01 =-1 AND tblCustomer.MS02=-1
【问题讨论】:
-
您能提供一些示例数据和建议的输出吗?还。声明@idSite ='MS01','MS02','MS03';无效 - 输入是否为逗号分隔列表?
-
为什么不使用
bit来保存您的标志/值1为真,0为假?为什么要传入一个字符串数组而不是为每个字段设置一个bit参数?注意:您当前的代码将无法运行,因为DECLARE @idSite ='MS01','MS02','MS03';无效/没有类型。 -
应该是:
declare @idSite table (MSFlag char(4)); insert @idSite (MSFlag) values ('MS01', 'MS02', 'MS03')? -
@idSite 是 SSRS 多值参数下拉列表。它根据下拉列表中的 idMailShot Location MS01 Location1 MS02 Location2 MS03 Location3 MS04 Location4 MS05 Location5 MS06 Location6 MS07 Location7 MS08 Location8 MS09 Location9 从下表中获取值 idMailshot
标签: sql-server string parameters case where-clause