简体   繁体   English

MS SQL / SSRS查询参数

[英]MS SQL/SSRS Query Parameter

This is going to be a simple one, I just can't figure it out. 这将是一个简单的过程,我只是无法弄清楚。

select * from table

Returns: 返回值:

|Item|Ordernumber|Color
|apple|2|Green|
|orange|2|yellow|
|apple|3|Red|

I want to filter on color 我想过滤颜色

select * from table 
where color = Green

I get, as expected 我得到了预期

|Item|Ordernumber|Color
|apple|2|Green|

I would like to show all items for the same order number IF the order contains any items with color Green 如果订单包含任何绿色的商品,我想显示同一订单号的所有商品

|Item|Ordernumber|Color
|apple|2|Green|
|orange|2|yellow|

I am creating a parameter in SSRS. 我在SSRS中创建一个参数。

You can first get the order number from the inner query (where color is green) and join it to the original table. 您可以先从内部查询(颜色为绿色)中获取订单号,然后joinjoin到原始表中。

select item, t.ordernumber, color 
from table t join
(select ordernumber from table 
where color = 'Green') x
on x.ordernumber = t.ordernumber

You have to create a parameter Color and put the parameter filter instead of hardcoding the color in the below code:- 您必须创建一个参数Color并放置参数过滤器,而不是在下面的代码中对颜色进行硬编码:-

select item, ordernumber, color 
from table where ordernumber in 
(select distinct ordernumber from table 
 where color = 'Green')

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

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