Results 1 to 5 of 5

Thread: How to declare variables in SP?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Contributing Member
    Join Date
    May 2006
    Answers
    78

    How to declare variables in SP?

    I am learning SQL server. When I am trying to learn stored procedure I have raised one queri that is How to declare variables in SP?

    For example I have created on stored procedure as given below:-
    CREATE procedure emp_DebugA
    (
    @IntIn int,
    @IntOut int OUTPUT
    )
    as

    Set @IntOut = @IntIn + 10

    Return

    and then I have typed command is
    Declare @NewInt int

    then I have typed command is
    exec emp_DebugA 5,@NewInt OUTPUT - when I am executing this command it is showing errror msg like "Must declare the variable '@NewInt'."


  2. #2
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: How to declare variables in SP?

    please find the details of stored procedures here.


  3. #3
    Junior Member
    Join Date
    Sep 2007
    Answers
    3

    Re: How to declare variables in SP?

    hi
    stored procedore usually contains a set of SQl command to be executed.u try out with some SQL COMMANDS

    U CAN excute a stored procedure as


    declare @a int (all input variable)
    set @a=5(giv input for all the varibles)
    exec (all inpu variable & output variables.output variables should be hav output key word)


  4. #4
    Junior Member
    Join Date
    Aug 2007
    Answers
    1

    Re: How to declare variables in SP?

    hi,
    bharathi ur SP is perfectly right, i just copied and excuted in query analyser and it worked perfectly fine.. i hope after creating the SP :
    ***********
    CREATE procedure emp_DebugA
    (
    @IntIn int,
    @IntOut int OUTPUT
    )
    as

    Set @IntOut = @IntIn + 10

    Return
    ***********
    and while exceuting the commnad below:
    *************
    Declare @NewInt int
    exec emp_DebugA 5,@NewInt
    *************
    u have taken both the lines into account. if u havent then only it would give such an error.


  5. #5

    Thumbs up Re: How to declare variables in SP?

    Hi Bharati_ark,

    The error is in the "exec" line of your coding.....

    Execute the Stored Procedure as given below and try:

    Declare @NewInt int
    exec emp_DebugA 5 , @IntOut=@NewInt output
    print @NewInt



    Best Wishes
    Sreedevi


    Last edited by Sreedevi Pidaparthi; 10-01-2007 at 08:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact