BULK INSERT with variable file name

后端 未结 2 472
忘了有多久
忘了有多久 2020-12-05 17:54

i am trying to bulk insert into Db using sql server 2005

Below is the code.

declare @path varchar(500) 
set @path = \'E:\\Support\\test.csv\'; 

Cre         


        
相关标签:
2条回答
  • 2020-12-05 18:04
    DECLARE @path varchar(50) = 'D:\ARQUIVOS_CARGAS\CABOS\FILE.prn'
    DECLARE @SQL_BULK VARCHAR(MAX)
    SET @SQL_BULK = 'BULK INSERT #TAB FROM ''' + @path + ''' WITH
            (
            CODEPAGE = ''ACP'',
            FIRSTROW = 1,
            FIELDTERMINATOR = ''tab'',
            ROWTERMINATOR = ''0x0a'',
            KEEPNULLS
            )'
    
    EXEC (@SQL_BULK)
    
    0 讨论(0)
  • 2020-12-05 18:26

    Try to use Dynamic SQL:

    declare @sql varchar(max)
    set @sql = 'BULK INSERT #mytable FROM ''' + @path + ''' WITH ...
    exec (@sql)
    
    0 讨论(0)
提交回复
热议问题