sql server - convert certain column names with comma separated string from sql table with conditions -
for example , have table different column names , boolean value below it,
case1 case2 case3 case4 1 0 1 0
what want retrieve,only column names 1 value. so, desired results query should case1,case3
desired output : case1,case3
there 1 row fetch sql query
is there way?
if understand correctly, use big case
statement:
select stuff(( (case when case1 = 1 ',case1' else '' end) + (case when case2 = 1 ',case2' else '' end) + (case when case3 = 1 ',case3' else '' end) + (case when case4 = 1 ',case4' else '' end) ), 1, 1, '') columns
Comments
Post a Comment