Cursorfetch:INTO 列表中声明的变量数量必须与所选列的数量匹配

Nej*_*the 4 sql sql-server sql-server-2000 cursor sql-update

declare @id int
declare @empid int
set @id = 0
declare @schedindate datetime
declare @ss nvarchar(100)
declare @indice nvarchar(2)
declare @FromDate datetime
declare @ToDate datetime
declare @TimeInR datetime
declare @TimeOutR datetime
set @FromDate = '2009-01-14'
set @ToDate = '2010-01-30'

Declare cc cursor for select distinct empid from ta_timecard where schedindate between @FromDate and @ToDate
open cc
fetch next from cc into @empid
while (@@fetch_status = 0)
begin
    set @id = @id + 1
    insert into ta_MonthlyAttendance (ID, EmpID) values (@id, @empid)

    declare cc2 cursor for select distinct schedindate, TimeInR, TimeOutR from ta_timecard where empid = @empid and schedindate between @FromDate and @ToDate
    open cc2
    fetch next from cc2 into @schedindate, @TimeInR
    while (@@fetch_status = 0)
    begin

        set @indice = cast(datediff(day, @fromdate, @schedindate) as nvarchar(4))
        set @TimeInR = (select TOP 1 ta_TimeCard.TimeInR from ta_TimeCard where (@schedindate between @FromDate and @ToDate) and EmpID=@empid)
        set @schedindate = (select TOP 1 ta_TimeCard.SchedInDate from ta_TimeCard where (@schedindate between @FromDate and @ToDate) and empid=@empid)
        set @ss = 'update ta_MonthlyAttendance set NOD ' + @indice  + ' = + dbo.ta_dayofweek('+ char(39) + convert(nvarchar(50), @schedindate, 102) + char(39) +' ) , TimeInR ' + @indice + ' =  + @TimeInR + where empid = ' + cast(@empid as nvarchar(20))
        execute sp_executesql @ss
        fetch next from cc2 into @schedindate, @TimeInR
end
close cc2
deallocate cc2
fetch next from cc into @empid
end
close cc
Deallocate cc
Run Code Online (Sandbox Code Playgroud)

此代码在“从 cc2 获取下一个到 @schedindate,@TimeInR”行中给出错误,我的错在哪里?找不到了。。谢谢。。

Raj*_*Raj 6

declare cc2 cursor for 
   select distinct schedindate, TimeInR, TimeOutR 
   from ta_timecard where empid = @empid 
    and schedindate between @FromDate and @ToDate
    open cc2
    fetch next from cc2 into @schedindate, @TimeInR
Run Code Online (Sandbox Code Playgroud)

您正在选择schedindate, TimeInR, TimeOutR但进入语句只有@schedindate, @TimeInR

拉吉