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.
| Author |
Topic |
|
Babli
Yak Posting Veteran
53 Posts |
Posted - 2007-09-19 : 00:33:11
|
| Hi, I have a requiremnet for a query in SQL 2005 where all the rows of a column needs to be concatenated.The number of rows may vary each time.ie,If input is:Col001-------abcdefghOutput should be like:abcdefghI am trying to avoid cursors...Please help... |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-09-19 : 00:40:37
|
| See: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Combine%20values%20from%20rows%20into%20a%20column |
 |
|
|
Babli
Yak Posting Veteran
53 Posts |
Posted - 2007-09-19 : 01:03:59
|
| Thanks guys...got the answer.Below is the query:DECLARE @strValues varchar(8000)SELECT @strValues = COALESCE(@strValues+',', '') + empnameFROM( SELECT DISTINCT Col001 FROM tab1) XORDER BY Col001SELECT [Result] = @strValues |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-09-19 : 04:07:04
|
| As usual, If you want to show them in front end, do concatenation thereMadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|
|
|