output variables

  • Hi,

       can somebody tell me how can i write a stored procedure which returns output variables as below

     

    @year2

    @year1

    @year1

     

    By this i mean @year = 2004

                        @year1 = 2005

                        @year = 2006

  • CREATE PROCEDURE dbo.OutputTest @Year int OUTPUT, @Year1 int OUTPUT, @Year2 int OUTPUT

    AS

    SELECT @Year = 2006,

        @Year1 = 2005,

        @Year2 = 2004

    GO

    DECLARE @returnValue int,

        @returnValue1 int,

        @returnValue2 int

    EXEC dbo.OutputTest @returnValue OUTPUT,@returnValue1 OUTPUT,@returnValue2 OUTPUT

    SELECT @returnValue,@returnValue1,@returnValue2

     

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • See the questions is i dont want to pass any input parameters in the stored procedure which you suggested

  • Well, in all fairness, your example isn't really telling me anything, it is about as vague as you can get.  Secondly, those are output parameters, not input parameters.  The only other way to get what you want (or what I think you may want) is to go this route:

    ALTER PROCEDURE dbo.OutputTest

    AS

    DECLARE @Year int,

        @Year1 int,

        @Year2 int

    SELECT @Year = 2006,

        @Year1 = 2005,

        @Year2 = 2004

    SELECT @Year AS 'Year', @Year1 AS 'Year1', @Year2 AS 'Year2'

    GO

     

    EXEC dbo.OutputTest

     

    If this doesn't do it for you, you'll have to give a better description of what it is you want.

     

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • >>> Hi,

    >>>    can somebody tell me how can i write a stored procedure which returns output variables as below

    >>> @year2

    >>> @year1

    >>> @year1

    Are two of the return variables the same name???

    >>> By this i mean @year = 2004

    >>>                @year1 = 2005

    >>>                @year = 2006

    Again two return variables of the same name, just different that the previous example.

    I have to wonder what class you are BSing your way through or what job you have managed to get and consistently scam.  You ask questions whose answer can be found with a simple BOL search or questions that make no sense at all (this question).  99% of people on this site ask reasonable questions about problems that they have been working on and have gotten stumped.  I think that YOU automatically post whatever homework assignment/job requirement you get immediately here, hoping that you never have to learn anything.  I mean, 180+ posts and you have yet to learn to post DDLs, example data and what you have been trying to solve the solution yourself.  This is assuming that you are trying to solve the problem yourself first.

    /endrant

  • <insert sound of applause here>

    Heh... I absolutely agree on these types of posts and I used to get mad as hell at some of these folks... then it dawned on me... they don't care, why should I?  Now, I just take another sip of my coffee and I move on to the next post.  I don't even bother asking for clarification anymore because I'm too busy with the other 99%   If more people did that and posts like the start of this thread simply went unanswered or we just posted a link to a "How to post a question site" with no other info, maybe some of these folks would get the hint.  If ya wanna teach a pig to fly, ya gotta give 'em "incentive"

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • In almost every one of his threads, I am tempted to ask where he works (he claims that this stuff isn't homework). I'm betting I could bill them insane amounts of money to clean up the mess.

  • How about we form a company so we all can benefit.

  • Heh... I'm all for that especially with present company

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff, there is no reason to get mad.

    Just change your attitude.

    As for me, I open topics from this nick only when I feel myself like a complete idiot or when I become frustrated because of some SQL code written by one of fellow developers.

    Then I open a topic from Best (thanks God there is at least one around) and see that life isn't that bad, everything could be much worse.

    So, don't try to teach a pig to fly, just take it as a visit to a shrink.

    And it's free!!!

    _____________
    Code for TallyGenerator

  • Heh... I love it, Serqiy... thanks for the great laugh

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 11 posts - 1 through 10 (of 10 total)

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