Solved

Fetch statement skewed

Posted on 2013-06-11
2
188 Views
Last Modified: 2013-06-11
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

0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
jonnidip earned 500 total points
ID: 39237808
You are missing INTO @id in your fetch next before END.
0
 

Author Closing Comment

by:lrbrister
ID: 39237865
johndip
Oh man...THAT'S embarrassing!
Thanks
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question