从逗号分隔的字符串中批量插入 [英] BULK INSERT from comma delimited string

查看:277
本文介绍了从逗号分隔的字符串中批量插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,其中一列包含以下数据:

I have a table with the following data in one column:

abc,2,2,34,5,3,2,34,32,2,3,2,2
def,2,2,34,5,3,2,34,32,2,3,2,2

我想获取这些数据并将其插入到另一个表中,使用逗号作为分隔符,就像您可以在BULK INSERT语句中指定FIELDTERMINATOR一样.

I want to take this data and insert it into another table, using the commas as delimiters, just like how you can specify the FIELDTERMINATOR in BULK INSERT statements.

是否可以使用T-SQL做到这一点?

Is there a way to do this using T-SQL?

推荐答案

您需要使用Split函数将字符串拆分为表变量,然后将这些值插入表中.

You need to use a Split function to split your string into a table variable, and then insert those values into your table.

其中有 ton 个拆分函数,各有优缺点,并有各种参数等等.

There are tons of those split functions out there, with various pros and cons and various number of parameters and so forth.

Here is one that I quite like - very nicely done, clearly explained.

使用该功能,您可以毫不费力地将列转换为其他表的各个条目.

With that function, you should have no trouble converting your column into individual entries for your other table.

这篇关于从逗号分隔的字符串中批量插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆