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
 Sql Comma seperated value

Author  Topic 

apvani
Starting Member

6 Posts

Posted - 2011-10-17 : 15:19:19
Hi,

I have a table with address column.
value in the address colum has values

when i select addr from table it gives

addrs
1000 expresslane
1500 southwestpark apt#10

I want to see output as

1000,expresslane
1500,southwestpark,apt#10

I am generating a report and user wants to see the address seperated with commas

can any one help on this please.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-17 : 21:54:22
how do you determine where to insert the commas ?

what if your address is like
"1500 south west park apt#10" ?



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jassi.singh
Posting Yak Master

122 Posts

Posted - 2011-10-18 : 01:26:07
hI YOU CAN USE stuff,

Please check below
SELECT STUFF('1000 expresslane',5,1,',')

Please mark answer as accepted if it helped you.

Thanks,
Jassi Singh
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-18 : 01:58:19
quote:
Originally posted by jassi.singh

hI YOU CAN USE stuff,

Please check below
SELECT STUFF('1000 expresslane',5,1,',')

Please mark answer as accepted if it helped you.

Thanks,
Jassi Singh


what about 1500 southwestpark apt#10? did you test it for all the sample data provided?



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

Go to Top of Page

apvani
Starting Member

6 Posts

Posted - 2011-10-18 : 12:26:43
Hi Jessi

Stuff works only when we know length and where to place comma.
which I dont know.

I think so this is not possible because I dont know exactly how to determine where do we have to place comma.

Thank you for the replies! Please let me know if you find anything around this issue.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-19 : 05:14:32
you didnt reply question asked by Tan yet

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

Go to Top of Page

sqlmaster555112
Starting Member

13 Posts

Posted - 2011-10-19 : 13:25:47
Hi try Replace function for it

update address set addr = replace(addr,' ',',')

Try this I think this may work if not let me know coz what this replace will do is that it will replace all spaces with ,

@sqlmaster

http://www.intelcs.com/SQL_Server_Consultant.aspx
Go to Top of Page
   

- Advertisement -