changeexpert
asked on
OSQL with stored procedure output parameter
Hi,
I tried to use osql to execute stored procedure with some input parameters and one output parameter, how I can do this.
thanks
I tried to use osql to execute stored procedure with some input parameters and one output parameter, how I can do this.
thanks
ASKER
Hi
Tried to run this and "stp_s_StoredProc" will accept 2 input parameters and 1 output parameter, the I will use the output parameter value as variable for another query. This line is included in another stored proc. Can I do this way instead of using inputfile/outputfile?
exec master..xp_cmdshell 'osql /U "SA" /P "ABC" /S "ServerName" /Q "stp_s_StoredProc"
Thanks
Tried to run this and "stp_s_StoredProc" will accept 2 input parameters and 1 output parameter, the I will use the output parameter value as variable for another query. This line is included in another stored proc. Can I do this way instead of using inputfile/outputfile?
exec master..xp_cmdshell 'osql /U "SA" /P "ABC" /S "ServerName" /Q "stp_s_StoredProc"
Thanks
yes you can specify the query to be executed via the Q (Query parameter instead)
but you not going to get the output variable that way....
what are you actually trying to do...
why do you need to run this in batch...
you maybe better off constructing a wrapper stored procedure to call the ones you want to invoke...
but you not going to get the output variable that way....
what are you actually trying to do...
why do you need to run this in batch...
you maybe better off constructing a wrapper stored procedure to call the ones you want to invoke...
ASKER
Hi,
I have stored proc that sit on SQL Server A and on SQL Server B will schedule a job to execute stored proc B on SQL B and inside this stored proc will execute stored proc A on SQL A and use the output parameter value in stored proc B.
I know I can use linked server to do execute stored proc A remotely. However, people do not like the idea of "Linked" two servers for security reason.
Thanks
I have stored proc that sit on SQL Server A and on SQL Server B will schedule a job to execute stored proc B on SQL B and inside this stored proc will execute stored proc A on SQL A and use the output parameter value in stored proc B.
I know I can use linked server to do execute stored proc A remotely. However, people do not like the idea of "Linked" two servers for security reason.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
but
osql -SserverName -ddatabasename -E -iinputfile.sql -ooutputfile.sql
and
inputfile.sql
would look something like
/*
run the xxx proc
*/
Declare @Outparm Varchar(8000)
Declare @RC Int
Exec @RC = ServerName.DabataseName.Ow
Print @Outparm
/* return sp execution status to DOS */
EXIT (Select @RC)
...
if not using a trusted connection then replace the -E with -Uuserid -Ppassword