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 2005 Forums
 Transact-SQL (2005)
 help in comma separated

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-08-29 : 07:38:06
CREATE FUNCTION [dbo].[GetCommaSeperatedString]

(@StationCode INT)

RETURNS VARCHAR(MAX)

AS

BEGIN

declare @listStr As VARCHAR(MAX)

-- Fill the table variable with the rows for your result set
SELECT @listStr = COALESCE(@listStr+',' , '') +

CASE CategoryCode

WHEN 'A' THEN 'String'

WHEN 'B' THEN 'Double'

END
FROM StationCategoryLink WHERE StationCode = @StationCode

RETURN @listStr

end

Output for this query is String,Double.

My question is when we add somemore CategoryCode columns in StationCategoryLink Table, like, A1, A2, B1,B2. How can i get the output as String,String1,String2,Double,Double1,Double2.

Can you please tell me how i can get the Comma seperated string for dynamically added columns.

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-29 : 07:39:00
You can do this without function.
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -