SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Execute dynamic sql does not work
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mary_itohan
Posting Yak Master

191 Posts

Posted - 04/25/2014 :  08:24:27  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

1510 Posts

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

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 04/25/2014 :  10:42:20  Show Profile  Reply with Quote
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

Edited by - TG on 04/25/2014 10:43:26
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000