Solved

Fetch statement skewed

Posted on 2013-06-11
2
183 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

895 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

11 Experts available now in Live!

Get 1:1 Help Now