Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Posts
    29

    Unanswered: Passing variables in a procedure

    Can you pass a variable to a procedure?
    Thus, in the code below, sp_employee_salary will be called 10 times, for employee 1 through 10
    -----------

    DECLARE @id INTEGER
    SELECT @id = 1

    WHILE (@id <= 10)
    BEGIN

    EXEC sp_employee_salary @id

    SELECT @id = @id + 1

    END

  2. #2
    Join Date
    Nov 2002
    Posts
    207
    Yes, I can.

  3. #3
    Join Date
    Feb 2004
    Posts
    9

    Procedure

    Yes ! you may create the procedure like
    Create Procedure Abc @StartID Int,
    @EndID int
    AS
    WHILE (@StartID <= @EndId)
    BEGIN
    EXEC sp_employee_salary @StartID
    SELECT @StartID = @StartID + 1
    END

    And you may execute this procedure like EXEC Abc 1, 10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •