This situation seems like it should be a simple task but I can’t come up with the solution. Imagine eight columns, four of which are bit columns (on/off) and the other four are reading values.
I want to create a view from this table, with another column for the range of the four reading values, based on those where their corresponding sensor alarm <> 1..
For examples purposes, we can use the following values.
Column1 – 12.44
Column1Alarm – 0
Column2 – 99.43
Column2Alarm – 0
Column3 – 4.43
Column3Alarm – 1
Column4 – 43.33
Column4Alarm – 0
For this example, the only values included in the range should be those coming from Column1, 2, and 4.
Thanks,
Tom
Editted as per @HLGM comments to make it a bit more robust.
Note that in it’s current form, I assume that when
NULLIf this does not suffice, OP might clarify what should be returned instead.
SQL Statement
Test script