1

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
2
  • 1
    Remove GO before BULK 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/… Commented Sep 5, 2016 at 9:03
  • Well I ended up with a different error now Msg 102, Level 15, State 1, Line 15 Incorrect syntax near '@TempTable'. Msg 319, Level 15, State 1, Line 17 Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon. Commented Sep 5, 2016 at 9:04

1 Answer 1

2

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

There are some old answers on stackoverflow that are deprecated then cause @ is certainly not working anymore

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.