SQL Query: data with comma

sql

Im using sql server 2005. i want data with comma. for example ['5000'],['5001'],..

but the last record should not include comma. Pls help me.

Query:

select '['''+convert(varchar,parcelid)+'''],' from sampletable

Best Answer

Try the COALESCE function

SELECT @groupedText = COALESCE(@groupedText, '') + [Text] + ','
     FROM Requirement
     WHERE CampaignId = @campaignId
     ORDER BY [Text]

Then you could try one of the string functions to kill the end comma

T-SQL string functions