sql - How to use Coalesce for string concatenation in a subquery? -


i'm trying string concatenate multiple row values 1 table using "coalesce", separated comma , list column in subquery.

something along line of

declare @assignto nvarchar(4000)  select  table1.columna table1.columnb ( select @assignto = coalesce(@assignto + ', ', '') + cast(name nvarchar(250)) table2     ... ) table1 

.....

i keep getting "incorrect syntax near '='."

if try execute subquery coalesce function called, its' fine. i.e

 declare @assignto nvarchar(4000)   select @assignto = coalesce(@assignto + ', ', '') + cast(name nvarchar(250))         table2             ...   select @assignto 

that's fine. question is, how include subquery?

thanks lot

ps: specific sql server 2000.

you can't include subquery: you'll have move udf.

in sql server 2005 can xml path technique. sql server 2000 have have separate scalar udf table access , concatenation


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -