Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 convert query into string with delimeters

Author  Topic 

barnabeck
Posting Yak Master

236 Posts

Posted - 2012-04-25 : 13:01:52
I need to add a column to a query that always returns one single record.

select some_columns from table1
where condition ='whatsoever'

now, the column I have to add is specified by this relationsship:

table2 on table1.link = table2.link and table2.whereclause ='whatsoever'

this relationsship returns more records and my goal is now to convert that column -or one dimensional array- into string, with komma delimiters.

value1
value2
.
.
valueN

becomes the scalar (value1, value2, ... valueN) that can be added to my inicial Query.

Anyone has a clue?
Regards, Martin

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-04-25 : 13:41:38
see here for example: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

If you need more help on this then please give us tables and sample data.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-25 : 14:35:30
do you mean this?


select some_columns,
stuff((select ',' + field from table2
where table1.link = link
and whereclause ='whatsoever'
for xml path('')),1,1,'')
from table1 t1
where condition ='whatsoever'



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

barnabeck
Posting Yak Master

236 Posts

Posted - 2012-05-02 : 11:38:57
I was too busy with other things all that time and just happen to get back on that matter...

Great STUFF!!! (literally spoken)

Works great and does exactly what I needed!

Thank you Visakh16!
Martin
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-02 : 19:34:08
quote:
Originally posted by barnabeck

I was too busy with other things all that time and just happen to get back on that matter...

Great STUFF!!! (literally spoken)

Works great and does exactly what I needed!

Thank you Visakh16!
Martin


welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -