Whats wrong with this SQL statement for table variable bulk insert

后端 未结 4 837
挽巷
挽巷 2020-12-10 14:25

I\'m trying to insert a CSV into a Temporary table and this SQL statement doesn\'t seem to work.

DECLARE @TempTable TABLE (FName nvarchar(max),SName nvarchar         


        
4条回答
  •  猫巷女王i
    2020-12-10 14:57

    You cannot BULK INSERT into a table variable. So this line:

    BULK INSERT @TempTable 
    

    Is what is causing the error.


    FYI, the simplest fix for this is probably just to use a #Temp table instead of a Table Variable. So your SQL code would change to this:

    CREATE TABLE #TempTable (FName nvarchar(max),SName nvarchar(max),
                              Email nvarchar(max));
    BULK INSERT #TempTable 
    FROM 'C:\52BB30AD694A62A03E.csv' 
    WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')
    

提交回复
热议问题