Hi Trey,
Thanks for getting back to me so quickly. I have been playing around with what you suggested all morning and I can't seem to get Proc1 to accept the value from Proc2 and use it to update another table correctly. I included a little bit of sample code that may help explain this a little better.
Okay... Here is Proc 2
CREATE PROCEDURE PROC2
@TXDETAILIDY numeric(28),
@output_var numeric(28) output
AS
/******************************************************************************
* Name: PROC2
* Created: 11/20/2001, S. Morton
* Desc: Looks up outcome of latest peer review record for update of TX
******************************************************************************/
DECLARE @_TxPeerReviewIDY numeric(28)
DECLARE @_TxPrvwOutcome numeric(28)
DECLARE @txpeerreviewidy numeric(28)
DECLARE @txprvwoutcome numeric(28)
DECLARE c_PRVW CURSOR
FOR
Select TxPeerReviewIDY, TxPrvwOutcome
FROM TTxPeerReview
WHERE TxDetailIDY = @TxDetailIDY
ORDER BY TxPeerReviewIDY Desc
BEGIN TRANSACTION
OPEN c_PRVW
FETCH NEXT FROM c_PRVW INTO @_TxPeerReviewIDY, @_TxPrvwOutcome
WHILE (@@FETCH_STATUS = 0)
BEGIN
select @txpeerreviewidy = @_txpeerreviewidy
select @txprvwoutcome = @_txprvwoutcome
FETCH NEXT FROM c_PRVW INTO @_TxPeerReviewIDY, @_TxPrvwOutcome
END
CLOSE c_PRVW
DEALLOCATE c_PRVW
If @txprvwoutcome is null
select @output_var = @txpeerreviewidy
If @txprvwoutcome is not null
select @output_var = 0
COMMIT TRANSACTION
--------------------------------------------------------------------------------------------------------------
Okay so Proc2 is either going to return @txpeerreviewidy or 0. On to PROC1....
CREATE PROCEDURE PROC1
@TXPEERREVIEWIDY numeric(28) output,
@v_TXDETAILIDY numeric(28),
@TXPRVWREFERRALDATE datetime = null
AS
/******************************************************************************
* Name: INS_TTXPEERREVIEW
* Created: 10/22/2001, S. Morton
* Modified:
* Desc: Inserts treatment peer review records
******************************************************************************/
DECLARE @RETURN int
DECLARE @MyIdent int
BEGIN TRANSACTION
Insert into TTXPEERREVIEW (
TXDETAILIDY,
TXPRVWREFERRALDATE)
values (
@v_TXDETAILIDY,
@TXPRVWREFERRALDATE)
Exec @Return = PROC2
@TXDETAILIDY = @v_TXDETAILIDY,
@OUTPUT_VAR = @MyIdent output
If @Return <> 0
Update TTXDETAIL
SET TxLockInd = 'Y'
Where TxDetailIDY = @v_TXDETAILIDY
If @Return = 0
Update TTXDETAIL
SET TxLockInd = 'N'
Where TxDetailIDY = @v_TXDETAILIDY
My insert procedure is working fine but PROC1 is having trouble getting the return value from proc2 and using it to update TTXDETAIL table with a value of Y or N. I'm not sure if this syntax is right since I have been pulling from a few different books. Any help you can give me is appreciated.
Thanks,
Stephany