SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 convert query into string with delimeters
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

barnabeck
Posting Yak Master

Spain
161 Posts

Posted - 04/25/2012 :  13:01:52  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8515 Posts

Posted - 04/25/2012 :  13:41:38  Show Profile  Visit webfred's Homepage  Reply with Quote
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

India
47188 Posts

Posted - 04/25/2012 :  14:35:30  Show Profile  Reply with Quote
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

Spain
161 Posts

Posted - 05/02/2012 :  11:38:57  Show Profile  Reply with Quote
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

India
47188 Posts

Posted - 05/02/2012 :  19:34:08  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000