sql server - Sql concatenation not working with case statement in sql -


i want concatenate multiple rows single text string checking few conditions using case statement. query returns last value rather concatenating values.

my sql query below

declare @str varchar(1000) set @str = '' select @str = @str +       case when substring(value,charindex('|',value)+1,len(value)) <> ''           '$' +replace(value,'|',' - ')      else           '$' +isnull(replace(value,'|',''),'')       end + ', '  dbo.sometable            print @str 

the common way row concatenation in sql server use for xml path

select @str = stuff((select case when substring(value,charindex('|',value)+1,len(value)) <> ''                            '$' +replace(value,'|',' - ')                           else '$' +isnull(replace(value,'|',''),'')                       end                @t xml path('')), 1, 1, '') 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -