当查询声明为 varchar 时,我无法获得正确的语法。 我下面的原始查询按预期工作:
WHERE location in ('+@location+') AND costcentre in ('+@costcentre+') AND drug_name in ('+@drug_name+')
如果为任何参数选择了多个值,则当前查询会出现语法错误:
SET @query = 'SELECT ....
WHERE location in ('+@location+') AND costcentre in ('+@costcentre+') AND drug_name in ('+@drug_name+')
我认为在这里,引号会打破字符串。如果我理解正确,这将起作用(更改 ['] -> [''] 并将变量与值连接起来(。
SET @query = 'SELECT ....
WHERE location in (''' + @location + ''') AND costcentre in (''' + @costcentre + ''') AND drug_name in (''' + @drug_name + ''')
如果上述方法不起作用,也尝试打印@query。
您可以尝试加入参数选择吗?我假设@location是一个参数,所以像这样:
Join(Parameters!location.Value, ",")
此链接也可能有所帮助: https://www.sqlchick.com/entries/2012/2/25/displaying-single-multi-valued-report-parameter-selections-i.html