tags:

views:

103

answers:

3

Hi All,

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

A: 

You can use regular expressions to remove the last comma or do it using your programming language (ASP etc. like a chop function or something).

http://weblogs.sqlteam.com/jeffs/archive/2007/04/27/SQL-2005-Regular-Expression-Replace.aspx

Alec Smart
is it possible to remove from same query
+1  A: 

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

CRice
thanku its working..:)
Geetha - if someone provides you with an answer, please check it as a good answer. It raises the answer to the top so that anyone else with your question sees the good answer right underneath of it, instead of having to search through all the other answers.
sql_mommy
A: 

Consider using XML for this purpose. The "aggregate concatenation" solution may not be reliable, because it is not clearly documented and supported. You can get rid of the final comma with SUBSTRING, as boon suggested.

See this thread.

Steve Kass