output parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RickBen
    New Member
    • Jun 2006
    • 2

    output parameters

    I have a stored proc that inserts a record into a table and sets three output parameter values. There is a contition that then inserts a record into a second table. If this insert does not occur, my calling application gets the output values, but if the conditional insert does occur, the output values are empty. Can anyone tell me why? Here is the code:

    CREATE Procedure usp_IMDetails_I nsertTempDtl
    @Orht_Id int,
    @Pdt_id int,
    @Ordt_UOM varchar(10),
    @Ordt_UnitsOrde red decimal(9,2),
    @Ordt_Cost decimal(9,2),
    @Ordt_Price decimal(9,2),
    @Ordt_DiscountP ct decimal(9,2),
    @Ordt_DiscountA mt decimal(9,2),
    @Ordt_ExtendedA mt decimal(9,2),
    @Ordt_AddDescTe xt varchar(50),
    @CreatedBy varchar(50),
    @Ordt_Id int output,
    @Pdt_ProductSKU varchar(25) output,
    @Pdt_ProdDesc varchar(60) output
    AS

    BEGIN

    BEGIN TRANSACTION
    INSERT INTO ordt_OrderDtl (
    Orht_Id,
    Pdt_Id,
    Ordt_UOM,
    Ordt_UnitsOrder ed,
    Ordt_Cost,
    Ordt_Price,
    Ordt_DiscountPc t,
    Ordt_DiscountAm t,
    Ordt_ExtendedAm t,
    Ordt_CreatedBy,
    Ordt_CreatedDat e )
    VALUES (
    @Orht_Id,
    @Pdt_Id,
    @Ordt_UOM,
    @Ordt_UnitsOrde red,
    @Ordt_Cost,
    @Ordt_Price,
    @Ordt_DiscountP ct,
    @Ordt_DiscountA mt,
    @Ordt_ExtendedA mt,
    @CreatedBy,
    GETDATE() )

    IF @@ERROR <> 0
    BEGIN
    ROLLBACK TRANSACTION
    RETURN -1
    END

    Set @Ordt_Id = @@Identity
    Select @Pdt_ProductSKU = pdt_productsku, @Pdt_ProdDesc = pdt_proddesc
    From pdt_product
    Where pdt_Id = @Pdt_Id

    IF LEN(@Ordt_AddDe scText) > 0
    BEGIN

    INSERT INTO nts_notes (
    NTS_FileAssn,
    NTS_ParTblId,
    NTS_Type,
    NTS_Text,
    NTS_Destination ,
    NTS_CreatedBy,
    NTS_CreatedDate )
    VALUES (
    'Ordt',
    @Ordt_Id,
    1,
    @Ordt_AddDescTe xt,
    0,
    @CreatedBy,
    GETDATE())

    IF @@ERROR <> 0
    BEGIN
    ROLLBACK TRANSACTION
    RETURN -2
    END
    END

    COMMIT TRANSACTION
    RETURN 1

    END
    GO
Working...