本文介绍了当我运行存储过程显示错误如下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER proc [dbo]。[shortcode_coursebookingrpt]( @ Fromdate varchar ( 20 ), @ Todate varchar ( 20 )) as 开始 声明 @ stud_id varchar ( 10 ), @ Mobileno varchar ( 15 ), @ Messagetext varchar ( 10 ), @ Msgdelivered varchar ( 20 ), @ Replymsg varchar ( 200 ) 创建 表 #TempTable(stud_id varchar ( 10 ),Mobileno varchar ( 100 ),Messagetext varchar ( 20 ),Msgdelivered varchar ( 20 ),Replymsg varchar ( 200 )) begin tran 声明 short cursor 选择消息,Mobileno,MSgdelivered,Replymsg 来自 Shortcode_Course_SMS 其中​​ Msgdelivered> @ Fromdate 和 Msgdelivered< @ Todate open short 获取 next 从短到 @Msgdelivered @@ Fetch_status = 0 开始 开始 tran 声明 coursebooked cursor 选择 s.stud_id,s.stud_mobile,sh.Mobileno,cbm.cmn_minor_code, case 当 cbm.cmn_minor_code = sh.Message 然后 ' 预订' end as Booked_Status, 案例 何时 cbm.cmn_minor_code<> ; sh.Message 然后 ' 未预订' end as UnBooked_Status 来自学生s,course_registration cr,co_batch_master cbm,Shortcode_Course_SMS sh,batch_course_registration bcr 其中 cr.stud_id = s.stud_id 和 substring(sh.mobileno, 3 , 20 )= s.stud_mobile 和 sh.Message = cbm.cmn_minor_code 和 bcr.cr_bill_no = cr.cr_bill_no 和 cbm.cbm_batch_id = bcr.bcr_batch_id 和 cr.cr_active = ' A' 和 cbm.cbm_active<> ' D' open coursebooked fetch next 从 coursebooked 进入 @ stud_id , @ Mobileno while @@ Fetch_status = 0 开始 插入 进入 #TempTable 值( @ stud_id , @ Mobileno , @Messagetext , @ Msgdelivered , @ Replymsg ) fetch next 从 coursebooked 到 @ stud_id , @ Mobileno end close coursebooked deallocate coursebooked commit tran fetch next 从短到 @ Msgdelivered 结束 close short deallocate short commit tran 选择 * 来自 #TempTable 结束 当我执行上述存储过程时显示错误如下 exec [shortcode_coursebookingrpt]'20140205','20140209' Cursorfetch:在...中声明的变量数INTO列表必须与所选列的列表匹配。 请帮助我。我上面的商店程序中出现了什么问题。 问候, Narasiman P. 解决方案 sanket saxena是正确的。 具体看看这些行 声明 short 光标 选择 消息,Mobileno,MSgdelivered,回复 来自 Shortcode_Course_SMS 其中 Msgdelivered> @ Fromdate 和 Msgdelivered< @ Todate open short fetch next 从短到 @ Msgdelivered 粗体位很重要。 你已经宣布你的光标将从每行检索四个项目,但是当你进行提取时,你只为结果提供了一个holder(变量)。四合一不去! 将光标声明更改为 声明 short cursor 选择 MSgdelivered 来自 Shortcode_Course_SMS 其中​​ Msgdelivered> @ Fromdate 和 Msgdelivered< @Todate OR,当你做FETCH时提供足够的变量 open short fetch next 从短到 @ Message , @Mobileno , @ Msgdelivered , @ ReplyMsg 你需要做一些与其他游标类似的东西 看起来你的SELECT列与INTO列中的相同光标。希望它有所帮助:) 您的 SELECT 和 FETCH .. .INTO 不匹配。 试试这个: 声明 short cursor 选择 消息,Mobileno, MSgdelivered ,Replymsg 来自 Shortcode_Course_SMS 其中​​ Msgdelivered> @ Fromdate 和 Msgdelivered< @ Todate 声明 coursebooked cursor for select s.stud_id ,s.stud_mobile ,sh.Mobileno ,cbm.cmn_minor_code, case 当 cbm.cmn_minor_code = sh.Message 然后 预订' 结束 as Booked_Status, case cbm.cmn_minor_code<> sh.Message 然后 ' 未预订' end as UnBooked_Status 来自 STUDENT s,course_registration cr,co_batch_master cbm,Shortcode_Course_SMS sh,batch_course_registration bcr 其中​​ cr.stud_id = s.stud_id 和 substring(sh.mobileno, 3 , 20 )= s.stud_mobile 和 sh.Message = cbm.cmn_minor_code 和 bcr.cr_bill_no = cr.cr_bill_no 和 cbm.cbm_batch_id = bcr.bcr_batch_id 和 cr.cr_active = ' A' 和 cbm.cbm_active&l吨;> ' D' 选定列并取出变量必须匹配! set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER proc [dbo].[shortcode_coursebookingrpt] (@Fromdate varchar(20),@Todate varchar(20))as begindeclare @stud_id varchar(10), @Mobileno varchar(15), @Messagetext varchar(10), @Msgdelivered varchar(20), @Replymsg varchar(200) create table #TempTable(stud_id varchar(10),Mobileno varchar(100),Messagetext varchar(20),Msgdelivered varchar(20),Replymsg varchar(200)) begin trandeclare short cursor for select Message,Mobileno,MSgdelivered,Replymsg from Shortcode_Course_SMS where Msgdelivered > @Fromdate and Msgdelivered < @Todateopen short fetch next from short into @MsgdeliveredWhile @@Fetch_status = 0 begin begin tran declare coursebooked cursor for select s.stud_id,s.stud_mobile,sh.Mobileno,cbm.cmn_minor_code, case when cbm.cmn_minor_code = sh.Message then 'Booked' end as Booked_Status, case when cbm.cmn_minor_code <> sh.Message then 'Not Booked' end as UnBooked_Status from STUDENT s,course_registration cr,co_batch_master cbm,Shortcode_Course_SMS sh,batch_course_registration bcr where cr.stud_id = s.stud_id and substring(sh.mobileno,3,20) = s.stud_mobile and sh.Message = cbm.cmn_minor_code and bcr.cr_bill_no = cr.cr_bill_no and cbm.cbm_batch_id=bcr.bcr_batch_id and cr.cr_active = 'A' and cbm.cbm_active <> 'D' open coursebooked fetch next from coursebooked into @stud_id,@Mobilenowhile @@Fetch_status = 0begin insert into #TempTable values(@stud_id,@Mobileno,@Messagetext,@Msgdelivered,@Replymsg) fetch next from coursebooked into @stud_id,@Mobilenoend close coursebookeddeallocate coursebookedcommit tran fetch next from short into @Msgdelivered endclose shortdeallocate shortcommit transelect * from #TempTableendWhen i execute the above store procedure shows error as followsexec [shortcode_coursebookingrpt] '20140205','20140209' Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.please help me.what is the problem in my above store procedure.Regards,Narasiman P. 解决方案 sanket saxena is correct.Specifically look at these linesdeclare short cursor for select Message,Mobileno,MSgdelivered,Replymsg from Shortcode_Course_SMS where Msgdelivered > @Fromdate and Msgdelivered < @Todateopen shortfetch next from short into @MsgdeliveredThe bits in bold are important.You have declared that your cursor will be retrieving four items from each row, but when you do the fetch you have only supplied one "holder" (variable) for the results. Four into One does not go!Either change the cursor declaration to declare short cursor for select MSgdelivered from Shortcode_Course_SMS where Msgdelivered > @Fromdate and Msgdelivered < @TodateOR, provide enough variables when you do the FETCH open shortfetch next from short into @Message, @Mobileno, @Msgdelivered, @ReplyMsgYou will need to do something similar with the other cursors tooSeems like your SELECT Columns are not same as INTO columns in the cursor. Hope it helps :)Hi,Your SELECT and FETCH...INTO are not matching.Try this:declare short cursor for select Message,Mobileno,MSgdelivered,Replymsg from Shortcode_Course_SMS where Msgdelivered > @Fromdate and Msgdelivered < @Todatedeclare coursebooked cursor for select s.stud_id,s.stud_mobile,sh.Mobileno,cbm.cmn_minor_code,case when cbm.cmn_minor_code = sh.Message then 'Booked' end as Booked_Status,case when cbm.cmn_minor_code <> sh.Message then 'Not Booked' end as UnBooked_Statusfrom STUDENT s,course_registration cr,co_batch_master cbm,Shortcode_Course_SMS sh,batch_course_registration bcr where cr.stud_id = s.stud_id and substring(sh.mobileno,3,20) = s.stud_mobile and sh.Message = cbm.cmn_minor_code and bcr.cr_bill_no = cr.cr_bill_no and cbm.cbm_batch_id=bcr.bcr_batch_id and cr.cr_active = 'A' and cbm.cbm_active <> 'D' Selected columns and fetched into variables must match! 这篇关于当我运行存储过程显示错误如下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 21:08