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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select all occurences of a string

Author  Topic 

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-03-23 : 12:22:59
hello,
I would like to select all occurences of a certain value as one output. ie a CSV column

eg
SELECT nickname,phone_number
FROM sms_phonebook
WHERE phone_number in ('5342543,2345234523,523452435') and username = hello

I would like to show the results in one column, with as a CSV

thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-23 : 12:32:18
declare @List
SELECT @List = coalesce(@List, '') + nickname + ' ' + phone_number
FROM sms_phonebook
WHERE phone_number in ('5342543','2345234523','523452435') and username = hello
SELECT @List

Go with the flow & have fun! Else fight the flow
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-03-23 : 12:38:03
What amazes me about this forum is not the precise answer i get, but the speed at which all threads are answerd.

Thanks Spirit
Afrika
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-03-23 : 12:51:24
One more question,

How do i implement this in an ASP page, query ? As a SP ?

thanks
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-23 : 13:09:29
a user defined function that returns varchar(8000)

Go with the flow & have fun! Else fight the flow
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-03-23 : 13:15:05
Ok thanks
Go to Top of Page
   

- Advertisement -