Wht is the problem with the code?Please help.

  • my code is as follows :

    ALTER PROCEDURE dbo.SP_GET_MG

    @MDSE_GRID_ID int,

    @RETURN_CODE int output,

    @RETURN_DESC varchar(200) output,

    @RCOUNT int output

    AS

    BEGIN TRY

    select * from MDSE_GRID where MDSE_GRID_ID=Coalesce( @MDSE_GRID_ID,MDSE_GRID_ID)

    SET @RCOUNT=@@ROWCOUNT

    SET @RETURN_CODE= 0

    SET @RETURN_DESC = 'Successful Execution.'

    END TRY

    BEGIN CATCH

    SET @RETURN_CODE = ERROR_NUMBER()

    SET @RETURN_DESC = ERROR_MESSAGE()

    END CATCH

  • Hi,

    Are you experiencing a specific error or issue with the code?

  • It would help if you’ll specify the values of the parameters that you use and the problems that you encountered. Do you have an error message? Does it do something else then what you expect it to do?

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • richabhadani (5/28/2009)


    my code is as follows :

    ALTER PROCEDURE dbo.SP_GET_MG

    @MDSE_GRID_ID int,

    @RETURN_CODE int output,

    @RETURN_DESC varchar(200) output,

    @RCOUNT int output

    Hi,

    From the parameter(output),i assume and write this

    ALTER PROCEDURE dbo.SP_GET_MG

    @MDSE_GRID_ID int,

    @RETURN_CODE int output,

    @RETURN_DESC varchar(200) output,

    @RCOUNT int output

    AS

    BEGIN

    select @RCOUNT = count(*) from MDSE_GRID

    where MDSE_GRID_ID=Coalesce( @MDSE_GRID_ID,MDSE_GRID_ID)

    IF @@ROWCOUNT 0

    begin

    SET @RETURN_CODE= 0

    SET @RETURN_DESC = 'Successful Execution.'

    select @RETURN_CODE,@RETURN_DESC,@RCOUNT

    end

    else

    begin

    SET @RETURN_CODE = ERROR_NUMBER()

    SET @RETURN_DESC = ERROR_MESSAGE()

    select @RETURN_CODE,@RETURN_DESC,@RCOUNT

    end

    END

    ARUN SAS

  • Looking at the sample code, I think I am right in saying basically if the select finds a record then you want to return success and if it doesnt then return the error number, couple of points;

    1. would it not be better to use an EXISTS; rather than SELECT, think this would be more effecient.

    2. If no records are found @@ROWCOUNT = 0 then you are returning the value of ERROR_NUMBER, wont this be blank as no error has actually occured?

    Sorry if i've mis-understood the situation.

  • Jackal (5/28/2009)


    Sorry if i've mis-understood the situation.

    Hi Jackal,

    Wait till the OP response.

    ARUN SAS

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply