问题
I have below text file having different words inside it:
My aim is to insert only 4 character words from the text file into a table variable which is @temp, using bcp command.
So, at the end, the table variable @temp will look like below:
回答1:
Create a table where you will store the data coming from your file:
create table import(WORDS nvarchar(100))Import data from file with bcp into the table created in the first step:
bcp [test].[dbo].[import] in d:\test.txt -c -TDeclare
@tablevariable:declare @table table ([ID] int identity(1,1), WORDS nvarchar(100))Insert into
@tablevariable only words with length = 4:insert into @table select WORDS from import where len(WORDS) <= 4
Now @table variable contains this data:
来源:https://stackoverflow.com/questions/52907024/how-to-read-text-file-into-table-variable-using-bcp-command