How do I use an IN statement in SSRS Formula

时间:2016-07-11 22:11:21

标签: sql reporting-services ssrs-2014

Is there an easy way to do an IN statement or something similar in a SSRS formula for an iff statement comparison without having to repeat a switch 16 times?

This is what I am looking to accomplish without having to write a statement or a separate OR ie(Fields!FieldName.Value = "01" OR Fields!FieldName.Value = "02"...etc) for each value:

=iif((Fields!FieldName.Value IN
("01","02","03","06","08","09","10","12","15","19"),"TypeA",
iff((Fields!ProdCode.Value IN ("04","07","11","13","14","16"),
"TypeB","TypeC")

3 个答案:

答案 0 :(得分:2)

Or this:

=switch( 
Instr( "," & "01,02,03,06,08,09,10,12,15,19" & ",", "," & Fields!FieldName.Value & ",") > 0  ,"TypeA",
Instr( "," & "04,07,11,13,14,16" & ",", "," & Fields!ProdCode.Value & ",") > 0  ,"TypeB",
True, "TypeC")

答案 1 :(得分:0)

Try this:

=Switch(
Array.IndexOf(Split("01,02,03,06,08,09,10,12,15,19",","), Fields!FieldName.Value)>-1,"TypeA",
Array.IndexOf(Split("04,07,11,13,14,16",","),Fields!FieldName.Value)>-1,"TypeB",
true,"TypeC"
)

Let me know if this helps.

答案 2 :(得分:0)

I have mocked up an example of joining to a table that is generated in the sql. This is more efficient than doing it in the report

SELECT a,b,c,d, etc
, Lookup.FieldName, Lookup.TypeLabel
FROM Tables INNER JOIN 
(SELECT '01' AS FieldName, "TypeA" as TypeLabel
UNION ALL
SELECT '02' , "TypeA"
UNION ALL
SELECT '03' , "TypeA"
UNION ALL
SELECT '04' , "TypeB"
UNION ALL
...

SELECT '18' , "TypeC"
UNION ALL
SELECT '19' , "TypeC") LookUp 
ON Tables.FieldName = Lookup.FieldName