I have a SQL query in SQL Server 2008 like this:
declare @Waited6_8 varchar(max) = 'true'
declare @Waited8_12 varchar(max) = 'false'
declare @Waited12_18 varchar(max) = 'true'
Select
choice = case when @Waited6_8 = 'true' then '6-8'
when @Waited8_12 = 'true' then '8-12'
when @Waited12_18 = 'true' then '12-18'
end
Here, I get 6-8 as the result.
What I would like to see is: 6-8, 12-18 as one string (not as different rows)
How can I get this? I appreciate if you help.
Thanks!
declare @Waited6_8 varchar(max) = 'true'
declare @Waited8_12 varchar(max) = 'false'
declare @Waited12_18 varchar(max) = 'true'
Select choice = isnull(case when @Waited6_8 = 'true' then '6-8' end + ', ','') +
isnull(case when @Waited8_12 = 'true' then '8-12' end + ', ','') +
isnull(case when @Waited12_18 = 'true' then '12-18' end,'')
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