[英]Is there a way I can use a calculated expression as a parameter in SSRS?
I'm not able to write the parameter in the data set like I have with two non-calculated parameters. 我无法像使用两个未计算的参数那样将参数写入数据集中。 If I'm going about this the wrong way any help is greatly appreciated to get me on the right track.
如果我以错误的方式进行操作,请多多帮助以使我走上正确的道路。
Data Set Query 数据集查询
SELECT
Inmast.fpartno
, inmast.fdescript
, inmast.fonhand
, inmast.fnonnetqty
, inmast.fcstscode
, inmast.fsource
, inmast.fprodcl
, inprod.fpc_desc
, inmast.fsafety
, inmast.fbook
, inmast.fonorder
, inmast.fproqty
, inmast.freordqty
From inmast
inner join inprod
on inmast.fac + inmast.fprodcl = inprod.fac + inprod.fpc_number
Where inmast.fcstscode = @Code and inmast.fsource = @Source
Calculated Expression 计算表达式
(inmast.fonhand
+ inmast.fonorder
+ inmast.fproqty
- inmast.fbook
- inmast.fnonnetqty
- inmast.fsafety < 0
) = @CalculatedExpression
You cannot use values from the DataSet to create a Parameter value. 您不能使用数据集中的值来创建参数值。 The Parameter is used to create the DataSet and therefore the values would not be available for the parameter.
该参数用于创建数据集,因此该值对于该参数将不可用。
I believe this will accomplish what you're trying to do. 我相信这将完成您想要做的事情。 First, your new query is:
首先,您的新查询是:
SELECT
Inmast.fpartno
, inmast.fdescript
, inmast.fonhand
, inmast.fnonnetqty
, inmast.fcstscode
, inmast.fsource
, inmast.fprodcl
, inprod.fpc_desc
, inmast.fsafety
, inmast.fbook
, inmast.fonorder
, inmast.fproqty
, inmast.freordqty
From inmast
inner join inprod
on inmast.fac + inmast.fprodcl = inprod.fac + inprod.fpc_number
Where inmast.fcstscode = @Code and inmast.fsource = @Source
and CASE WHEN
(inmast.fonhand
+ inmast.fonorder
+ inmast.fproqty
- inmast.fbook
- inmast.fnonnetqty
- inmast.fsafety
) < 0 THEN 0 ELSE 1 END = @CalculatedValue
Next for your new Parameter named @CalculatedValue you will create two default values. 接下来,对于名为@CalculatedValue的新参数,您将创建两个默认值。
- label "Less than 0" and value 0
标签“小于0”,值0
- label "More than 0" and value 1
标签“大于0”,值1
What is happening is the case statement will return 0 if the sum of your calculation is less than 0. It will return 1 if it is >= 0. Your @CalculatedValue will just match to that value to filter your results appropriately. 发生的情况是,如果您的计算总和小于0,则case语句将返回0。如果> = 0,它将返回1。您的@CalculatedValue将与该值匹配以适当地过滤结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.