简体   繁体   English

将查询更改为SSRS中的表达式

[英]Changing query to expression in SSRS

I am trying to turn a SQL query into an expression in SSRS; 我正在尝试将SQL查询转换为SSRS中的表达式; however, it seems like the behavior of the expression is not as I expected. 但是,表达式的行为似乎不符合我的预期。 I have done this in the past, and I do not remember it behaving this way. 我过去曾经这样做过,但我不记得它的表现方式。 I am hoping someone cna shed some light on whether there is a better way to do this than I am currently trying. 我希望有人可以向我阐明目前是否有比我现在尝试的更好的方法。 I know I can use a Stored Procedure to work around this, but as this is a one time thing, I was hoping to avoid that. 我知道我可以使用存储过程来解决此问题,但是由于这是一回事,所以我希望避免这种情况。

="if '" & Join(Parameters!pParam.Value,"") & "' = 'X'
select * from table 1
else
select * from table 2"

I expected this to be treated as a single string, but it is not. 我希望将其视为单个字符串,但事实并非如此。 I need to do the following to treat it as a single string. 我需要执行以下操作以将其视为单个字符串。

="if '" & Join(Parameters!pParam.Value,"") & "' = 'X' " & 
"select * from table 1 " & 
"else " & 
"select * from table 2"

Or I can put it all one line, which is easier with something short, but not really feasible with longer scripts. 或者,我可以将所有内容都放在一行中,这虽然简短,但比较容易,但较长的脚本却不可行。

why not simply go like this in your dataset instead.. 为什么不简单地像这样在您的数据集中呢?

select * from table1 where @pParam.Value = 'X' 
union all 
select & from table2 where @pParam.Value <> 'X'

I am assuming that both tables return matching columns and data types. 我假设两个表都返回匹配的列和数据类型。

Always select your columns explicitly rather than select *! 始终明确选择列,而不要选择*!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM