Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Execute dynamic sql does not work

Author  Topic 

mary_itohan
Posting Yak Master

191 Posts

Posted - 2014-04-25 : 08:24:27
Hi guys,
pls advise on this



set @sql = 'BULK INSERT CSV_TESTING
FROM ''d:\MAM-NAP.csv''
WITH
(
FIELDTERMINATOR = '','',
ROWTERMINATOR = ''\n''
);'





exec @sql



as I get the error

Msg 2812, Level 16, State 62, Procedure upload_bulk_insert_MAM_NAP_Step1, Line 22
Could not find stored procedure 'BULK INSERT CSV_TESTING
FROM 'd:\MAM-NAP.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
);'.


_____________________


Yes O !

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-04-25 : 08:28:23
See example C here: http://technet.microsoft.com/en-us/library/ms188332.aspx
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-04-25 : 10:42:20
you need to enclose the string in parentheses:

exec (@sql)

EDIT:
otherwise it assumes you are trying to exec an SP

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -