cursor that uses its stored procedure''s parameter

  • I wrote a SP that contains a cursor. This cursor needs to use the SP parameter for the cursor query.

    I had the error that said that parameter must be declared. Please help. Thanks a lot!!!

    create procedure spr_test

    @param1 int as

     

    declare test_cursor cursor for

     select emp_id, emp_name from employee where emp_id = @param1

    .... -> got error as 'Must declare the variable @param1'

  • Using your example I do not get an error when I run.

    use pubs

    create procedure spr_test

    @param1 int

    as

    declare test_cursor cursor for

     select emp_id, fname from employee where emp_id = @param1

    -- CLOSE test_cursor

    DEALLOCATE test_cursor

    go

    spr_test @param1 = 1

     

  • Thanks, Ray M. I'm able to get it works after removes some t-sql commands lay between. I'm really appreciate your helps!!!

Viewing 3 posts - 1 through 2 (of 2 total)

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