SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Execute a stored procedure from a batch file


Execute a stored procedure from a batch file

Author
Message
nivecse
nivecse
SSC-Enthusiastic
SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)

Group: General Forum Members
Points: 151 Visits: 66
Hi,

I have to execute an SP from .bat file. What I have done is, I have created a .bat file with the following entry:

%OpMode% %msISQL% Some_File.sql


The "Some_File.sql" file contains the following execute statement:

execute [dbo].[Stored_Proc_Name] 1,0,0,''

The connection parameters for the database are in another .bat file.

When I execute the .bat file, am getting the following error:

Msg 170, Level 15, State 1, Server SERVER_NAME, Line 1
Line 1: Incorrect syntax near 'ÿ'.

Any help is appreciated..

Thanks,
Nivetha
WayneS
WayneS
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9835 Visits: 10569
I would suspect that the line you're executing isn't correct.
Try putting an "echo %OpMode% %msISQL% Some_File.sql" to ensure that it's being called properly (you may need a "pause" in there also).

Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings

nivecse
nivecse
SSC-Enthusiastic
SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)SSC-Enthusiastic (151 reputation)

Group: General Forum Members
Points: 151 Visits: 66
Hi,

Am getting the following entry in my log file when i put echo before
%OpMode% %msISQL% Some_File.sql:

CALL C:\sql\core\MS_ISQL_Driver.bat Some_File.sql
executing MS_ISQL_Driver.bat with input file Some_File.sql

---- START ERROR HANDLING -----
BATCH TERMINATED by unexpected error "in SQL Script Some_File.sql". Skipping remaining batch.

I think there is problem with the Some_File.sql, means, my way of executing the stored procedure might be wrong..

I have entry as:

execute [dbo].[Stored_Procedure_Name] 1,0,0,''

Is this right?
jregan 3066
jregan 3066
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 0
I have the same error message. I am running a batch file that calls a SQL file that runs a pretty simple update script. When I run the script manually, it runs fine. The same syntax that applies to the call to this script is used to call multiple other scripts on a nightly basis, and the others all work. Here is the error message (which I know is not very helpful by itself):

Incorrect syntax near 'ÿ'.

Like I said, the same batch file contains calls to 6 SQL scripts, all with the same credentials and syntax.
WILLIAM MITCHELL
WILLIAM MITCHELL
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2124 Visits: 3061
Are you actually getting the lowercase y with the two little dots over it?

If so, your sql file is saved in Unicode, not standard ASCII. Open the sql file in SSMS, click file ~ save as, and then on the Save button click the little down-arrow at the right - select "save with encoding" and then select 1252 and then you can save it in ASCII.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search