Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Fetch statement skewed

My code below works, but @id is never changed.


DECLARE @id int
DECLARE @htid VARCHAR(1000)
SET @htid = '71886,71887,71888,71889'
DECLARE htid_cursor CURSOR FOR
SELECT [str] FROM dbo.Parselist(@htid,',')

OPEN htid_cursor;
FETCH NEXT FROM htid_cursor
INTO	@id;


-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
   -- This is executed as long as the previous fetch succeeds.
   INSERT INTO [dbo].[EmailQueue]
        ( [Application] ,
          [FromLine] ,
          [ToLine] ,
          [Subject] ,
          [MessageSource]
        )
	VALUES
        ( 'Test' , -- Application - varchar(255)
          'noreply@nightingalenurses.net' , -- FromLine - varchar(3000)
          'lbrister@nightingalenurses.net' , -- ToLine - varchar(3000)
          'Test Insert' , -- Subject - varchar(max)
          @id
        );	

   FETCH NEXT FROM htid_cursor;
END

CLOSE htid_cursor;
DEALLOCATE htid_cursor;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jonnidip
jonnidip
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry Brister

ASKER

johndip
Oh man...THAT'S embarrassing!
Thanks