Nezir Zahirović

MSSQL return a single line value consisting of multiple rows of values

In  this  post I'll show  you how  simple you can create one string  value from multiple sql rows values.

In  picture  below we had  some  sql data table  with 4  rows .


Now,  our task is  to create one  single line  string  value  from columns  vorname and nachname:
so we  use  sql  code :


We see on picture  above code  that  we  use to complete successfully our task :)

Copy code :

declare @str varchar(300)
select
@str = case
when @str is null
THEN vorname + ' '+nachname
else @str + ' , ' + vorname + '  '+nachname
end
FROM dbo.tbl_CorectNumber
WHERE (anrede ='Herr' )
SELECT @str
SHARE
    Blogger Comment
    Facebook Comment

3 comments: