Using IN (or similar) with IIF
I want to be able to program something like the following in SSRS: =iif(Parameters!SO.value in (1, 2, 3, 4), "Yes", "No") Currently, I could get away with the following: =iif(Parameters!SO.value = 1 OR Parameters!SO.value = 2 OR Parameters!SO.value = 3 OR Parameters!SO.value = 4, "Yes", "No") But I want to find a shorter way of writing this query - using IN would have been ace but it doesn't like it. Any ideas I could try?You can't dangle the bogus carrot of possible reconciliation in front of me whilst riding some other donkey
August 4th, 2011 6:50am

This looks like switch would be your better choice. SWITCH( Parameters!SO.value=1, "Yes", Parameters!SO.value=2, "Yes", Parameters!SO.value=3, "Yes", Parameters!SO.value=4, "Yes", 1=1, "No" )Eyespi20
Free Windows Admin Tool Kit Click here and download it now
August 4th, 2011 9:35am

Using switch is even worse as I have, in some cases 20 elements to analyse which is where the ELSE comes in handy for the IIF. I literally needed a short hand version of my query as I stated above.You can't dangle the bogus carrot of possible reconciliation in front of me whilst riding some other donkey
August 4th, 2011 9:42am

Using your parameters the way you are, you are pretty much stuck with either your IIF statement or the switch statement in SSRS. The only other solution would be to add code to your query to satisfy your statement. alter myTable add valid bit default 1 update myTable set valid=0 where @myParam in (1,2,3,4) Then use your IIF(Fields!valid.Value=0, "Yes", "No") Margaret Norkett Database Administrator Commercial Foodservice Repair
Free Windows Admin Tool Kit Click here and download it now
August 4th, 2011 10:21am

It would be better to do it in query by using IN. If you want to achieve this is reporting then write a custome code to set a flag for values(1,2,3,4) . And use that flag in your iif
August 4th, 2011 4:13pm

Hi Ded_innit, You may create a dataset dsOptionsForSO with following SQL: Select CASE WHEN @SO IN (1,2,3,4) THEN 'Yes' ELSE 'No' END as Result1 Then create internal parameter say, Par1 and default it to Result1 column of dsOptionsForSO. Then use Par1 instead of your IIF statement =iif(Parameters!SO.value in (1, 2, 3, 4), "Yes", "No") Remember to mark as an answer if this post has helped you.
Free Windows Admin Tool Kit Click here and download it now
August 4th, 2011 5:08pm

HI Ded, Thanks for your post and other ones’ professional reply. According to your description, you would like to verify whether your parameter value is contained in a special integer collection. Actually, there is no available expression works like this at present, but we can make a workaround by using custom code, please follow the steps below to have a try: 1. In Design view, right-click the design surface outside the border of the report and click Report Properties. 2. Click Code. 3. In Custom code, type the code. Errors in the code produce warnings when the report runs. The following example creates a custom function named IsContainedInt that verify whether the value is contained in the limited integer Array. Dim IntArray() As Integer = New Integer() {1, 2, 3,4} Public Function IsContainInt(ByVal fa As Integer) As Boolean For Each valInt As Integer In IntArray If valInt = fa Then Return True End If Next Return False End Function 4. The following example shows how to pass a parameter value named SO to this function in an judgment expression: =IIf(Code.IsContainInt(Parameters!SO.Value),"Yes", "No") If you have anything unclear, please feel free to let me know. Thanks, Bill Lu Please remember to mark the replies as answers if they help and unmark them if they provide no help.
August 8th, 2011 1:27am

Public Function IsContainIn(ByVal fa As Integer, ByRef IntArray as Integer()) As Boolean Dim nI As Integer For nI = 0 To IntArray.GetUpperBound(0) If IntArray(nI) = fa Then Return True End If Next Return False End Function Usage: =IIF(Code.IsContainIn(Parameters!SO.Value,new Integer(){1, 2, 3}), "Yes", "No") Remember to mark as an answer if this post has helped you.
Free Windows Admin Tool Kit Click here and download it now
August 9th, 2011 11:21pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics