文本文件导入SQL中(数据文件的完整路径动态变化) 语句怎样写?
我写了一个SQL语句让文本文件导入SQL数据库中
如下:
BULK INSERT [dbo].[ta] FROM 'c:\1.txt'
WITH (
DATAFILETYPE = 'char',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
但现在我要求数据文件的完整路径即'c:\1.txt'不确定可动态变化怎样写?
[解决办法]
--动态SQL,try:exec('BULK INSERT [dbo].[ta] FROM '+@PATH+'WITH ( DATAFILETYPE = ''char'', FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'' )')
[解决办法]
try
exec('BULK INSERT [dbo].[ta] FROM '''+@PATH+''' WITH ( DATAFILETYPE = ''char'', FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'' )')