Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Bob Meason writes "I have used Rob Volks parsing CSV to a single record using the Tally table. It worked flawlessly as detailed.However, here's a twist: What would you do if you wanted to create a single record with TWO words (2 CSV values). Like this:Author Word Word2------------- ------------ ------------Shakespeare A RoseShakespeare by anyshakespeare other name.........etc.I tried using the ID field as a kind of index, starting with 1,3,5,7,9,etc. Then taking Word using ID and Word2 using ID+1.Unfortunately, it did not work.Do you have a suggestion or solution."
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2006-09-25 : 10:57:21
declare @table table( Author varchar(100), Word varchar(100), Word2 varchar(100))insert into @tableselect 'Shakespeare', 'A', 'Rose' union allselect 'Shakespeare', 'by', 'any' union allselect 'shakespeare', 'other', 'name'declare @csv varchar(4000)select @csv = isnull(@csv, '') + Word + ',' + Word2 + ','from @tableselect @csv = left(@csv, len(@csv) - 1)select @csv-- A,Rose,by,any,other,name