DECLARE Cur1 CURSOR FOR SELECT ClientID From Folder;
OPEN Cur1 FETCH NEXT FROM Cur1 INTO @ClientID; WHILE @@FETCH_STATUS = 0 BEGIN PRINT 'Processing ClientID: ' + Cast(@ClientID as Varchar); DECLARE Cur2 CURSOR FOR SELECT UID FROM Attend Where ClientID=@ClientID; OPEN Cur2; FETCH NEXT FROM Cur2 INTO @UID; WHILE @@FETCH_STATUS = 0 BEGIN PRINT 'Found UID: ' + Cast(@UID as Varchar); FETCH NEXT FROM Cur2 INTO @UID; END; CLOSE Cur2; DEALLOCATE Cur2; FETCH NEXT FROM Cur1 INTO @ClientID; END; PRINT 'DONE'; CLOSE Cur1; DEALLOCATE Cur1;