在我的SSRS报告构建器中,我为我的一个数据集(名称为dsTagAttributes)设置了表达式。查询类型是文本。
这是查询表达式
="select m.TagName, ta.descriptor, t.[State] from MasterTags m inner join TagAttributesClassic ta on m.ID = ta.TagID inner join TagStates t on t.ID = m.StateID where m.PIServerID = @ServerID and t.[State] = @State and m.MetaData1 = @Station " & Parameters!AndOr.Value & "m.MetaData2 = @Device"
上面的查询表达式有一个参数,它在select语句中连接。
参数@AndOr
数据类型为文本,默认值为“或”,参数可见性设置为隐藏(下面的屏幕截图)。我已设置此参数,因为它将用于在报表运行时期间将数据集结果从or
动态更改为and
。
我的查询命令文本可能出现什么问题?
非常感谢任何帮助。
答案 0 :(得分:0)
您可以针对数据源运行Profiler以查看查询。
我认为问题在于你错过了"'"每个varchar值之前和之后(@State
,@Station
)。
我不会用这种方式来使用OrAnd条件
您可以像
一样修改TSQL...
AND
(m.MetaData2 = @Device AND @OrAnd = 'AND')
)
OR
(m.MetaData2 = @Device AND @OrAnd = 'OR')
请确保正确放置')'
和'('
,具体取决于业务逻辑。