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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 SQL stored procedure in Batch
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

acnsql
Starting Member

2 Posts

Posted - 05/04/2015 :  07:35:22  Show Profile  Reply with Quote
Hi,
I am using stored procedure in batch which is as
osql /UABC /P ABC /S SERVER1 /d database1 /q "exit(test_sp)".

when I am running this procedure through batch, its getting executed successfully but still I am getting an errorlevel of -100 in batch output.

Request your help on this.

Thanks in advance

Edited by - acnsql on 05/04/2015 07:46:55

SwePeso
Patron Saint of Lost Yaks

Sweden
30421 Posts

Posted - 05/04/2015 :  10:15:45  Show Profile  Visit SwePeso's Homepage  Reply with Quote
osql /UABC /P ABC /S SERVER1 /d database1 /q "exec test_sp".



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA

Edited by - SwePeso on 05/04/2015 10:15:57
Go to Top of Page

Kristen
Test

United Kingdom
22859 Posts

Posted - 05/04/2015 :  14:39:00  Show Profile  Reply with Quote
We generate a temporary script file (we do that, dynamically, from the BATCH file but a static/fixed file will do) which contains:

DECLARE @intErrNo int 
EXEC @intErrNo=dbo.MySProc @Param1=xxx, @Param2=yyy
:EXIT(SELECT @intErrNo)

The BATCH file contains:

SQLCMD -d MyDatabase -i MyTempScript.SQL -o X:\MyPath\MyProcessName.OUT -b -l 300 -S . -E >>X:\MyPath\MyProcessName.ERR
IF ERRORLEVEL 1 GOTO SQL1_Error

I presume OSQL is similar
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30421 Posts

Posted - 05/05/2015 :  07:01:00  Show Profile  Visit SwePeso's Homepage  Reply with Quote
You are still running T-SQL commands.
http://blog.sqlauthority.com/2009/01/05/sql-server-sqlcmd-vs-osql-basic-comparison/



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

acnsql
Starting Member

2 Posts

Posted - 05/05/2015 :  07:21:17  Show Profile  Reply with Quote
I am using OSQL for calling the stored procedure
Go to Top of Page

Kristen
Test

United Kingdom
22859 Posts

Posted - 05/05/2015 :  10:15:21  Show Profile  Reply with Quote
Use whichever you like (OSQL is obsolete though), my point was to set an ERRORLEVEL (using EXIT) that the command line can make available within a BATCH file or similar. I didn't find a way to directly set the ERRORLEVEL with the return result of an SProc UNLESS I used an intermediate / temporary script, as described above.
Go to Top of Page
  Previous Topic Topic Next 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.04 seconds. Powered By: Snitz Forums 2000