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

    Unanswered: Cursor / Query batch error

    I get this error when I have two cursors declared and execute and the same time (line by line). Any idea on how to correct this?


    DECLARE CURSOR must be the only statement in a query batch.

  2. #2
    Join Date
    Nov 2002
    Posts
    207
    Can you pls. provide the sql/syntax you are using?

  3. #3
    Join Date
    Apr 2004
    Posts
    29

    Example Code

    DECLARE rt_cursor_1 CURSOR FOR
    SELECT a.id, b.height, a.gp, a.pts, a.treb, a.ast
    FROM elias_cum_life a, elias_final_roster b
    WHERE a.season_type = 'RS' AND
    a.league = 'NBA' AND
    a.id = b.alpha_id
    GO
    IF exists (select *
    from sysobjects
    where name = "projection_data_1"
    and type = "U"
    and uid = user_id()
    )
    DROP TABLE projection_data_1
    GO
    OPEN rt_cursor_1
    CREATE TABLE projection_data_1 (id varchar(9), height varchar(5), gp decimal(10,2), pts decimal(10,2), treb decimal(10,2), ast decimal(10,2))
    EXEC procedure_projection_model_1 KIR346075
    CLOSE rt_cursor_1
    DEALLOCATE CURSOR rt_cursor_1





    DECLARE rt_cursor_2 CURSOR FOR
    SELECT a.id, b.year, b.gp, b.pts, b.treb, b.ast
    FROM projection_data_1 a, elias_cum_yrly b
    WHERE a.id = b.id AND
    b.season_type = 'RS' AND
    b.league = 'NBA'
    GO
    IF exists (select *
    from sysobjects
    where name = "projection_data_2"
    and type = "U"
    and uid = user_id()
    )
    DROP TABLE projection_data_2
    GO
    OPEN rt_cursor_2
    CREATE TABLE projection_data_2 (id varchar(9), year varchar(7),
    season_gp decimal(10,2), season_pts decimal(10,2), season_treb decimal(10,2), season_ast decimal(10,2),
    rt_gp decimal(10,2), rt_pts decimal(10,2), rt_treb decimal(10,2), rt_ast decimal(10,2))
    EXEC procedure_projection_model_2
    CLOSE rt_cursor_2
    DEALLOCATE CURSOR rt_cursor_2

  4. #4
    Join Date
    Apr 2004
    Posts
    29
    Anyone have a solution

  5. #5
    Join Date
    Nov 2002
    Posts
    207
    How about a GO after deallocating the cursor?

Posting Permissions

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