My problem with output parameters

  • Is there anyway we can check the value returned by output parameter...

    Like for example

    Create sp_Example (@param datetime output)

    As

    Select @param = getdate()

    return 0

    I have 2 issues with this code

    1. There is no way i can check if calling application is recieving the output from my sql server side. And the code is really working or not. There is no way to do unit testing for this code.

    2. There is no way i can see what is being returned from sql server.

    How to solve these 2 issues since this discourages me to use output parametes in my code??

  • 1. There is no way i can check if calling application is recieving the output from my sql server side. And the code is really working or not. There is no way to do unit testing for this code.

    2. There is no way i can see what is being returned from sql server.

    Which application is calling it? Visual Studio code?

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • It can be anything.. y should i be concered with it.. I just need to be sure my code does return the values..

  • I created your procedure in my Sandbox database (by the way, your create proc statement is missing something).

    You can run the procedure like this to see what is being returned.

    DECLARE @rc int

    DECLARE @param datetime

    -- TODO: Set parameter values here.

    EXECUTE @rc = [Sandbox].[dbo].[sp_Example]

    @param OUTPUT;

    select @rc, @param;

    GO

  • It can be anything.. y should i be concered with it.. I just need to be sure my code does return the values

    The same reason why any Application Developer should be concerned about the code he/she runs against your database. It's a partnership you will never get away from.

    The application developer can debug his code and step into your procedure, to confirm the results are passed.

    Do you get results when executing the SP?

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • what will @rc and @param return in your code??

  • itskanchanhere (3/23/2012)


    It can be anything.. y should i be concered with it.. I just need to be sure my code does return the values..

    You should be concerned that your code is returning the output expected based on the input values provided and that if there is any error conditions that can't be handled in your code that the proper exception(s) and error messages and information are returned, or if exceptions are propagated that they are the ones expected by the calling code.

  • itskanchanhere (3/23/2012)


    what will @rc and @param return in your code??

    Create your stored proc (after fixing your create statement) and give the code I gave you a try. You asked how you could check the values returned from your proc, right?

  • No there is soem syntax problem in the create procedure .. i dint try it before posting.. Anyways what id the calling application is a separate group that does not co opersate with u.. In that case I need to do unit testing my self to justify myself

  • Also, look up EXECUTE (EXEC) in Books Online if you want more info on how it works and its syntax.

  • itskanchanhere (3/23/2012)


    No there is soem syntax problem in the create procedure .. i dint try it before posting.. Anyways what id the calling application is a separate group that does not co opersate with u.. In that case I need to do unit testing my self to justify myself

    Regarding the code you posted, no kidding, I told you that earlier.

    If you don't cooperate with the other development group you all have a problem. You all should be on the same team, not fighting each other.

  • Have you fixed the code you posted earlier to create your test procedure and try running it with the code I gave you?

  • new project, need to instal it first before trying

  • itskanchanhere (3/23/2012)


    new project, need to instal it first before trying

    It will probably all work out fine

  • patrickmcginnis59 (3/23/2012)


    itskanchanhere (3/23/2012)


    new project, need to instal it first before trying

    It will probably all work out fine

    awesome linky Patrick, thank you! 😀

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 15 posts - 1 through 14 (of 14 total)

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