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