I've been reading up on tutorials and other stackoverflow answers but I just can't seem to get this to work. I'm running the following script and I keep getting.
USE my_db
GO
DECLARE @TempTable TABLE (
insz nvarchar(max),
firstname nvarchar(max),
middlename nvarchar(max),
lastname nvarchar(max),
birthdate date,
street nvarchar(max),
streetnumber nvarchar(max),
mailbox nvarchar(max),
city nvarchar(max),
zipcode nvarchar(max)
)
GO
BULK INSERT @TempTable
FROM 'C:\Workspaces\magdasync\src\main\examples\my_file.csv'
WITH
(FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n')
GO
Msg 102, Level 15, State 1, Line 2 Incorrect syntax near '@TempTable'.
asked Sep 5, 2016 at 9:01
1 Answer 1
It is not possible to bulk insert in table variable. so you can use temp table.
USE magdasync
GO
CREATE Table #TempTable(
insz nvarchar(max),
firstname nvarchar(max),
middlename nvarchar(max),
lastname nvarchar(max),
birthdate date,
street nvarchar(max),
streetnumber nvarchar(max),
mailbox nvarchar(max),
city nvarchar(max),
zipcode nvarchar(max)
)
GO
BULK INSERT #TempTable
FROM 'C:\Workspaces\magdasync\src\main\examples\magdasync_input_example.csv'
WITH
(FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n')
GO
answered Sep 5, 2016 at 9:57
1 Comment
kenny
There are some old answers on stackoverflow that are deprecated then cause @ is certainly not working anymore
lang-sql
GO
beforeBULK
statement. Table variable is visible only in its scope. Also it turns out that you can not insert into table variable: stackoverflow.com/questions/14113820/…