Solved

What is wrong with this SQL SP that it keeps giving me a Cursorfetch error?

Posted on 2009-04-06
2
182 Views
Last Modified: 2012-05-06
I keep getting  this error with the code example below.  I've looked at a million times and I must be missing something.  Maybe a fresh pair of eyes can spot the obvious mistake.  Thank you!  This is urgent!

ex = {"Cursorfetch: The number of variables declared in the INTO list must match that of selected columns."}
USE [OrderEntry_prodSQL]
GO
/****** Object:  StoredProcedure [dbo].[InsertBOLTransfer]    Script Date: 04/06/2009 12:49:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[InsertBOLTransfer]
--(@Bolnum nvarchar(25), @HeatID int)
 
AS
 
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
   -- DECLARE @BLNum as nvarchar(25)
DECLARE @Control as int
DECLARE @HeatID as int
DECLARE @CoilNumber as nvarchar(25)
 
DECLARE @FinishedSize as nvarchar(15)
DECLARE @Grade as nvarchar(15)
DECLARE @HeatNumber as nvarchar(20)
DECLARE @TotalWeight as int
DECLARE @NoOfCoils as int
DECLARE @VendorName as nvarchar(25)
DECLARE @RodSize as nvarchar(10)
DECLARE @VendorPO as nvarchar(15)
DECLARE @VendorNumber as int
--DECLARE @DateReceived as smalldatetime
DECLARE @ID as int
 
    DECLARE CoilsCursor CURSOR FAST_FORWARD FOR
	 SELECT     Control,HeatNumber,Grade,FinishedSize,SUM(Weight) AS TotalWeight,COUNT(*) AS NoOfCoils,HeatID,VendorName,VendorPO,RodSize,HeatID,VendorNumber
		FROM         tblPickList
        GROUP BY tblPickList.Control, tblPickList.HeatNumber, tblPickList.Grade, tblPickList.HeatID, tblPickList.FinishedSize,VendorName,VendorPO,RodSize,VendorNumber
	OPEN CoilsCursor
FETCH NEXT FROM CoilsCursor INTO @Control,@HeatNumber,@Grade,@FinishedSize,@TotalWeight,@NoOfCoils,@HeatID,@VendorName,@VendorPO,@RodSize,@VendorNumber
 
WHILE @@FETCH_STATUS = 0
BEGIN
    
    --PRINT 'Coil: ' +@CoilNumber
INSERT INTO tblBOLTransfer
(
Control,
HeatID,
HeatNumber,
Grade,
FinishedSize,
NetWeight,
NoOfCoils,
VendorName,
VendorPO,
RodSize,
VendorNumber
)
 
VALUES
(
@Control,
@HeatID,
@HeatNumber,
@Grade,
@FinishedSize,
@TotalWeight,
@NoOfCoils,
@VendorName,
@VendorPO,
@RodSize,
@VendorNumber
)
 
SELECT @ID =@@IDENTITY
FROM tblBOLTransfer
 
	FETCH NEXT FROM CoilsCursor INTO @Control,@HeatNumber,@Grade,@FinishedSize,@TotalWeight,@NoOfCoils,@HeatID,@VendorName,@VendorPO,@RodSize,@VendorNumber
	
 
END
 
CLOSE CoilsCursor
DEALLOCATE CoilsCursor
 
--DELETE FROM tblReceiving WHERE BOLNumber = @Bolnum

Open in new window

0
Comment
Question by:jvalescu
  • 2
2 Comments
 
LVL 12

Expert Comment

by:udaya kumar laligondla
ID: 24079495
DECLARE CoilsCursor CURSOR FAST_FORWARD FOR
       SELECT    
 Control,
HeatNumber,
Grade,
FinishedSize,
SUM(Weight) AS TotalWeight,
COUNT(*) AS NoOfCoils,
HeatID,
VendorName,
VendorPO,
RodSize,
HeatID,
VendorNumber
            FROM         tblPickList
        GROUP BY tblPickList.Control, tblPickList.HeatNumber, tblPickList.Grade, tblPickList.HeatID, tblPickList.FinishedSize,VendorName,VendorPO,RodSize,VendorNumber
      OPEN CoilsCursor
FETCH NEXT FROM CoilsCursor
INTO
@Control,
@HeatNumber,
@Grade,
@FinishedSize,
@TotalWeight,
@NoOfCoils,
@HeatID,
@VendorName,
@VendorPO,
@RodSize,
@VendorNumber
 
you are selecting one more than the no of variables
0
 
LVL 12

Accepted Solution

by:
udaya kumar laligondla earned 500 total points
ID: 24079502
HeatID is missing in the selection list or is added extra at the into part
 
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is there any Easy way to copy CSV to SQL Server using C# 3 91
Delete from table 6 48
Why is the output of this function is like this? 4 39
What is this datetime? 1 20
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In this article I will describe the Copy Database Wizard 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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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