sim.plified.com

Chris Pollock

Chris Pollock - web developer (PHP/mySQL & ASP.NET)
undivided… my thoughts on world, family, church, business, technology and Jesus Christ (all in all)

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
Technorati Tags: ,,

One Comment, Comment or Ping

  1. sulfur_scratch

    jesus christ….

Reply to “T-SQL Loop through SELECT Statement”

Things I see

Emerging LocustEmerging LocustSimonbackgroundSimon - 2 monthsSimon - 2 monthsSimon - 2 monthsSimon - 2 monthsSimon - 2 monthsPlaying in the YardPlaying in the YardPlaying in the YardPlaying in the YardNY to MO to NY GatheringNY to MO to NY GatheringNY to MO to NY Gathering

Chris Pollock

Web Developer - proficient in both PHP and ASP.NET.
Rochester, New York

View my web developement site.

View Chris Pollock's LinkedIn profile

My Pictures

Emerging LocustEmerging LocustSimonbackgroundSimon - 2 monthsSimon - 2 monthsSimon - 2 monthsSimon - 2 monthsSimon - 2 monthsPlaying in the YardPlaying in the YardPlaying in the YardPlaying in the YardNY to MO to NY GatheringNY to MO to NY GatheringNY to MO to NY Gathering