如何将两个拆分列插入两列表中

时间:2013-04-12 12:22:13

标签: sql-server-2005

我有一个函数,它将字符串和一个字符作为输入,它将按此字符分割字符串并返回列

DECLARE @strIndustryID varchar(MAX)='1,2,3,4,5,6,7,44,55,66,77,88'
DECLARE @strIndustryDescription varchar(MAX)='desc1|desc2|desc3|desc4|desc5|desc6|desc7|desc44|desc55|desc66|desc77|desc88'
DECLARE @COUNT INT=0
SELECT * FROM dbo.Split(@strIndustryID,',');
SELECT * FROM dbo.Split(@strIndustryDescription,'|');

并按第一个查询输出

1
2
3
4
5
6
7
44
55
66
77
88

和第二次查询

desc1
desc2
desc3
desc4
desc5
desc6
desc7
desc44
desc55
desc66
desc77
desc88

现在我想输出

<pre lang="vb">desc1
Col1 col2
2   desc2
3   desc3
4   desc4
5   desc5
.
.
.
.

我希望将这些列插入到table1中,table1中有一列名为col1和col2

我该怎么做?

1 个答案:

答案 0 :(得分:0)

DECLARE @strIndustryID varchar(MAX)='1,2,3,4,5,6,7,44,55,66,77,88'
DECLARE @strIndustryDescription varchar(MAX)='desc1|desc2|desc3|desc4|desc5|desc6|desc7|desc44|desc55|desc66|desc77|desc88'
DECLARE @COUNT INT=0
SELECT a, b  FROM
(
SELECT a FROM dbo.Split(@strIndustryID,',') t1 CROSS JOIN 
SELECT b FROM dbo.Split(@strIndustryDescription,'|') t2
) AS main
WHERE a = REPLACE(b, 'desc', '')