Friday, March 23, 2012

Help with a switch statement.

Hey again,

So here's what I'm trying to do: I have three columns of data. Sometimes only one of the columns will contain a value while others may contain a null. If two or three contain a value it will be the same. So if I'm building a table in the layout designed and I want the value of the table to be the value stored in these columns. In pseudocode it looks like this:

Switch(column1 and column2 are null, value = column3, if column1 and column3 are null, value = column2, otherwise, value = column1)

Something like that where column1 is the default so if column 1 has a value then set the textbox value to it otherwise find a column that has it. I know that at least one column will definitely have a value. Anyone that can provide guidance on how to execute these I would appreciate it greatly.

Thank you!

Hello Keith,

Try this:

=Switch(

Fields!Column1.Value is nothing and Fields!Column2.Value is nothing, Fields!Column3.Value,

Fields!Column1.Value is nothing and Fields!Column3.Value is nothing, Fields!Column2.Value,

1 = 1, Fields!Column1.Value

)

Hope this helps.

Jarret

|||Is 'nothing' the keyword for null? I kept typing in null and it gave me invalid identifier or something, I couldn't figure out how to check it in the switch.|||

Yes sir.

You could also use Len(Fields!Column1.Value) > 0 for that check.

Jarret

|||I'll try it out, thanks alot!|||Do you, or anyone else, know how I would do this with the actual query, so they they are all consolidated into one field? I know I need to use the case statement but I can't get the syntax right. Basically it's the same situation, I'm taking from three different places, one or more may have a value but I just want to end up with one column populated. Thank you!|||Looks like you could use a COALESCE() to do this in a query. COALESCE will return the first non null value in the list of values. Ex. COALESCE(Value1, Value2, Value3) will return the first non null value checking them in order of value1, value2 and value3.|||That's great, thank you!sql

No comments:

Post a Comment