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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -