June 26, 2002 04:26 PM

Using T-SQL to Concatenate Data Into a Variable

Rating: (0)
SQL Server Magazine
InstantDoc ID #25262

Can I create in T-SQL a stored procedure that loops through rows and concatenates data into a variable, as I do in Visual Basic (VB)?

There are two basic ways to solve problems in T-SQL: row-by-row processing or set-based logic. Row-by-row processing is similar to what you might do in a procedural language such as VB. Usually, you implement row-by-row processing in T-SQL by using a T-SQL—based cursor. You can use a cursor to loop through a data set, concatenating data to a...

...This article is for paid Professional Members only.

Already a Professional Member? Please log in now:

NOT A PROFESSIONAL MEMBER? YOU CHOOSE:

Professional Membership

Monthly

Annual

VIP Membership

Monthly

Annual

Add a Comment

Had no idea that the ability to concatenate strings existed in that fashion. Wish it were possible just to SUM(string, 'delimiter'), but this is pretty cool. Planning to use it in one of my reports. Just need to find a way to not have ', prepended or appended to each set now. Thanks for the tip.

PETER1/26/2006 11:47:04 AM


Spectacular. Thanks so much, this was exactly what I needed to learn.

Anonymous User 8/23/2005 12:32:50 PM


Great never thought of the 2nd listing example this is going to save me lots of time. Great Work !!!!!!!!!!!!!!!!!!!

Anonymous User 4/29/2005 7:43:27 AM


I meant Listing 3 not 2 - Great

Anonymous User 4/29/2005 7:38:45 AM


Would love to see more set based examples. Actually an article that shows diff things that SQL programers write cursors to do and show simple set based examples of the same would be wonderful! Anyone know of any nice examples?

Anonymous User 1/31/2005 11:14:26 AM


Just what I needed

StevieL8/11/2004 7:24:29 AM


You must log on before posting a comment.

Are you a new visitor? Register Here
GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS