T-SQL Loop through SELECT Statement
I recently changed the a data structure in calendar program and needed to move some data around. Normally to do this I would write an external app to query the database and rewrite the data. This time I decided to try using T-SQL. It worked great. Below is my code:
DECLARE @Event_ID int DECLARE my_cursor CURSOR FOR SELECT Event_ID FROM ITS_CALENDAR_EVENTS_LIST WHERE EVENT_SA_Flag = 1 OPEN my_cursor FETCH NEXT FROM my_cursor INTO @Event_ID WHILE @@FETCH_STATUS = 0 BEGIN INSERT INTO ITS_CALENDAR_EVENTS_TO_FLAGS (Event_ID, Event_Flag_ID) VALUES (@Event_ID, 1) FETCH NEXT FROM my_cursor INTO @Event_ID END CLOSE my_cursor DEALLOCATE my_cursor










No Comments, Comment or Ping
Reply to “T-SQL Loop through SELECT Statement”