How to cast variables in T-SQL for bulk insert?

后端 未结 6 1551
面向向阳花
面向向阳花 2020-11-30 10:20

The following code gives an error (its part of a T-SQL stored procedure):

-- Bulk insert data from the .csv file into the staging table.
DECLARE @CSVfile nva         


        
6条回答
  •  忘掉有多难
    2020-11-30 10:48

    you have to engage in string building & then calling EXEC() or sp_executesql BOL has an example:

    DECLARE @bulk_cmd varchar(1000)
    SET @bulk_cmd = 'BULK INSERT AdventureWorks2008R2.Sales.SalesOrderDetail
    FROM '':\\'' 
    WITH (ROWTERMINATOR = '''+CHAR(10)+''')'
    EXEC(@bulk_cmd)
    

提交回复
热议问题