.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get Values of a Column in a Single Variable

Posted By:Lakhan Pal Garg       Posted Date: June 30, 2010    Points: 10    Category: SQL Query    URL: http://www.dotnetspark.com  

Get all the values of a single column in a variable separated by comma.

DECLARE a Variable and set the Size of the variable according to your requirement. here in this code i have mentioned MAX.

Now Using :

SELECT @TempString = @TempString + CityName +',' FROM Tbl_City

Statement we can append all the values in @TempString separated by comma.

@TempString contains a extra comma at the end. so we need to remove that with the help of :


Sample Code:

SET @TempString = ''
SELECT @TempString = @TempString + CityName +',' FROM Tbl_City
SELECT SUBSTRING(@TempString,0,LEN(@TempString))


Lakhan Pal Garg


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend