Solved

Fetch statement skewed

Posted on 2013-06-11
2
182 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
2 Comments
 
LVL 13

Accepted Solution

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

Author Closing Comment

by:lrbrister
Comment Utility
johndip
Oh man...THAT'S embarrassing!
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now