I have the below set of T-SQL statements. Where a cursor is loaded with about 500 IDs. And for each ID a set up update statements are executed.
declare @id int
declare @ids cursor
set @ids=cursor fast_forward read_only for
select id from table_id;
open @ids
fetch next from @ids into @id
while @@FETCH_STATUS=0
begin
update table2 set qty2=0 where id=@id;
update table3 set qty3=0 where id=@id;
fetch next from @ids into @id
end
close @ids
deallocate @ids
When I run this using pyodbc in python by setting autocommit=True, the update statements for only a few IDs are run, but not for every ID. Why is that behavior?
Here is the python statement used.
tsqlString = "declare @id int ... deallocate @ids"
con = pyodbc.connect(connection_string, autocommit=True))
cursor = con.cursor()
cursor.execute(tsqlString)
cursor.close()
con.close()