5

I'm using SSRS (VS2008) and creating a report of work orders. In the detail line of the report table, I have the following columns (with some fake data)

WONUM  |  A  |  B  | Hours
ABC123 |  3  |  0  |   3
SPECIAL|  0  |  6  |   6
DEF456 |  5  |  0  |   5
GHI789 |  4  |  0  |   4
OTHER  |  0  |  2  |   2

As you can kind of see, all work orders have a work order number (WONUM) as well as a total # of hours (HOURS). I need to put the hours into either column A or column B based on WONUM. I have a list of specifically named work orders (in the example, they would be "SPECIAL" and "OTHER") which would cause the HOURS value to be put in column B. If the WONUM is NOT a special named one, then it goes in column A. Here's what I WANTED to put as the expression for column A and column B:

Column A: =IIF(Fields!WONUM.Value IN ("SPECIAL","OTHER"), 0, Fields!Hours.Value)
Column B: =IIF(Fields!WONUM.Value IN ("SPECIAL","OTHER"), Fields!Hours.Value, 0)

But as you're probably aware, Fields!WONUM.Value IN ("SPECIAL","OTHER") is not a valid method of doing this! What is the best way to make this work? I cannot flag it in the SQL query in any other way for other reasons so it must be done in the table.

Thanks in advance for any and all help!

1
  • If it's just the two WONUMs that you're trying to filter out, is there any reason why you can't just use an OR in the IIf statement?
    – thyme
    Commented Jun 27, 2012 at 21:10

2 Answers 2

5

Try this, (Using InStr() function)

IIF(InStr(Fields!WONUM.Value,"SPECIAL")>0 OR InStr(Fields!WONUM.Value,"OTHER")>0, 0, Fields!Hours.Value)

IIF(InStr(Fields!WONUM.Value,"SPECIAL")>0 OR InStr(Fields!WONUM.Value,"OTHER")>0, Fields!Hours.Value,0)
1
  • Thanks for another option. I used Chris Latta's answer in my report.
    – D.R.
    Commented May 20, 2013 at 4:20
3

If it's just the two WONUMs then you can do this:

Column A:

=IIF((Fields!WONUM.Value <> "SPECIAL") AND (Fields!WONUM.Value <> "OTHER"), Fields!Hours.Value, 0)

Column B:

=IIF((Fields!WONUM.Value = "SPECIAL") OR (Fields!WONUM.Value = "OTHER"), Fields!Hours.Value, 0)

or use the same formula in each column for consistency and swap the field/0 at the end.

4
  • What happens if you have more than 2? There's no "IN" equivalent?
    – PeterX
    Commented Jul 23, 2014 at 1:11
  • There are things that you can do, for example using IndexOf, depending on your requirements. If you have a specific problem you should ask it as a new question and we can deal with it there. Commented Jul 24, 2014 at 4:27
  • I moved my logic to an SQL IN statement to help simplify the SSRS logic.
    – PeterX
    Commented Jul 24, 2014 at 23:30
  • It is usually the best idea to let SQL do the heavy lifting for you if possible. Commented Jul 26, 2014 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.