January 20, 2012 at 5:04 am
Hi,
I have to run two procedures using .bat file.
To run second procedure i need output patameter of first procedure.
Please help me in this regard.
DECLARE @P1 INT, @P2 INT
--SETTING VALUES TO VARAIBLES
EXEC SP1 @P1, @P2 OUT
EXEC SP2 @P2
how to run this script in batch file.
Regards,
Venugopal.rr
January 20, 2012 at 5:09 am
Why do you need to execute these in a batch file?
Perhaps SSIS might be a better solution?
For the sake of simplicity, you may want to nest your stored procs (not necessarily best practise!!) but this will avoid you having to call both from the batch file.
_____________________________________________________________________
Disclaimer - The opinions expressed by the mouth are not necessarily those of the brain
January 20, 2012 at 5:46 am
By using SSIS we can do, but i want to do it using .bat file
Based on value of first procedure output parameter, I will decide to execute second procedure.
DECLARE @P1 INT, @P2 INT
--SETTING VALUES TO VARAIBLES
EXEC SP1 @P1, @P2 OUT
IF @P2 = 1
EXEC SP2 @P1
January 20, 2012 at 9:12 am
you can write a small .net wrapper program to execute the procedure and return the output param as an exit code (assuming it is an integer).
Another option is to modify the the stored procedure to write the output param to a table that can be queried from the batch file.... or, call the procedure from another procedure that writes to a table.
The probability of survival is inversely proportional to the angle of arrival.
January 22, 2012 at 2:53 pm
January 24, 2012 at 10:25 am
Thanks for your reply,
sqlcmd -s servername -q "exit(exec testproc)"
@echo %errorlevel%
stored procedure returns an integer value with select statement
ex: select -1; return;
when i run the procedure using .bat file(bat file script given as above), i am getting errorlevel as 1.
for any other value i am getting as specified in the procedure. if i return 100 i am getting 100.
but for -1 i am getting 1. why i am getting the value different for -1.
I need the reason why it behaving differently for -1 only.
Regards,
venugopal.rr
January 24, 2012 at 10:30 am
well, SQL server has no problem returning negative numbers...maybe it's a command line limitation?
CREATE PROCEDURE checkstate @param int
AS
return @param;
GO
DECLARE @return_status int;
EXEC @return_status = checkstate -1;
SELECT 'Return Status' = @return_status;
GO
Lowell
January 24, 2012 at 10:43 am
Interesting, I didn't know that a negative %errorlevel% was possible.
-- Gianluca Sartori
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply