I have a table like this:
col1 col2 col3
111 1 1
222 1 0
333 0 1
444 0 0
Here col2 = 1
means col1
is commercial, col3 = 1
means col1
is retail as well. How do I get a result like below?
ID Description
111 Commercial
111 Retail
222 Commercial
333 Retail
You can do it with a UNION ALL
:
SELECT ID = col1, 'Commercial' FROM MyTable WHERE col2=1
UNION ALL
SELECT ID = col1, 'Retail' FROM MyTable WHERE col3=1
Uses almost the same as above but in a single result set
Select ID = col1, t.Description
from MyTable
cross apply (select Description = 'Commercial' where col2 = 1 union
select Description = 'Retail' where coll3 = 1)t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With