Link to home
Start Free TrialLog in
Avatar of techques
techques

asked on

How to write a return value in a SP and how another SP get the return value from that SP?

Hi

There are 2 MSSQL stored procedures:
SP_A which will select a field from a table and return it.
SP_B which needs to declare a variable and the return value from SP_A will be assigned to it

How can I write those 2 stored procedures?
and, the SP_B need to write transaction to ensure commit otherwise rollback.

Is there any full source code example?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

a procedure to "return" a single variable is written like this:
CREATE PROCEDURE SP_A 
( @result VARCHAR(100) OUTPUT
)
AS
BEGIN
  SELECT @result = somecolumn FROM sometable WHERE <some condition goes here>
END

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial