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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to transform two sets of CSV's into 1 table

Author  Topic 

R
Constraint Violating Yak Guru

328 Posts

Posted - 2011-08-03 : 10:59:51
I have two sets of values:

DECLARE @id1 nvarchar(max)
DECLARE @id2 nvarchar(max)
SELECT
@id1 = '3,6,9,10,',
@id2 = '56,75,87,98,'

which I need to transform into a single table variable with these values as columns, like this:

@MyTableVariable
----------------
Col1 Col2
3 56
6 75
9 87
10 98

Currently I have a function that transforms each nvarchar variable into its own table variable with an ID column (identity(1,1)) included. I then perform a JOIN on each table and select the results into a new table variable. It works fine, but I was wondering if there is a faster way to achieve this please?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-08-03 : 11:10:33
That would be how I would do it, if I had to do it. If the code is inefficient, more likely than not, the function or script you are using to do the splitting may be the culprit. If that indeed is the case, you may want to look up Jeff Moden's article here and specifically, the function in Fig. 21 of that article.
Go to Top of Page

R
Constraint Violating Yak Guru

328 Posts

Posted - 2011-08-04 : 05:06:39
Okay that's great - thanks!
Go to Top of Page
   

- Advertisement -