Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Posts
    54

    Unanswered: Problem wit sp_execute SQL

    I have to make a large number of updates (about 29k) so I generated teh update statements into a table and am trying to sue sp_executesql to run them. Here is my code:

    Declare @SQLState NVARCHAR(500)

    Declare Code Cursor
    for
    select SQLState from updates
    open Code
    FETCH NEXT FROM Code
    into @SQLState
    While @@fetch_Status = 0
    Begin
    Exec sp_executesql @SQLState

    FETCH NEXT FROM Code
    END

    CLOSE Code
    DEALLOCATE Code

    IT appears to run succesfully, but the updates never happen - I get the following results for each update line:

    UPDATE REEmployeeEvent SET UpdatedByEmployeeID= '00013' Where UpdatedByEmployeeID='00279'

    (1 row(s) affected)

    (0 row(s) affected)

    Any ideas what I am doing wrong?

    BTW - If I run the statements manually, they do work.

    Thanks for any help!

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    is there any particular reason why you want to use such a non-standard method to execute a script?

    Why not execute dump them to a file, and execute the file as a single batch? At least that way you could visually inspect the scripts for correctness.

    What you are trying to do here seems risky at best.

Posting Permissions

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