[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Fetch statement skewed

Posted on 2013-06-11
2
Medium Priority
?
197 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 2000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

656 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