本文介绍了如何使用bcp命令将文本文件读取到@table变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面的文本文件中有不同的单词:
I have below text file having different words inside it:
我的目标是使用bcp命令将文本文件中的仅4个字符的单词插入到@temp
的表变量中.
My aim is to insert only 4 character words from the text file into a table variable which is @temp
, using bcp command.
因此,最后,表变量@temp
将如下所示:
So, at the end, the table variable @temp
will look like below:
推荐答案
-
创建一个表,您将在其中存储来自文件的数据:
Create a table where you will store the data coming from your file:
create table import(WORDS nvarchar(100))
使用bcp将文件中的数据导入第一步中创建的表中:
Import data from file with bcp into the table created in the first step:
bcp [test].[dbo].[import] in d:\test.txt -c -T
声明@table
变量:
declare @table table ([ID] int identity(1,1), WORDS nvarchar(100))
仅将长度为4的单词插入@table
变量:
insert into @table
select WORDS
from import
where len(WORDS) <= 4
现在@table
变量包含以下数据:
Now @table
variable contains this data:
这篇关于如何使用bcp命令将文本文件读取到@table变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!