当我执行存储过程显示错误 [英] When I Exeucte The Store Procedure Shows Error

查看:175
本文介绍了当我执行存储过程显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的商店程序如下



My Store Procedure as follows

  set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[Presea_Intakerpts]
as 

begin
set nocount on

declare @BatchID varchar(20), @MajorName varchar(100), @Minorcode varchar(10), @Intake_Capacity int,
		@BatchStartdate varchar(15), @BatchEnddate varchar(15)

Create table #TempTable (MajorName varchar(100), Minorcode varchar(10), BatchStartdate varchar(15), BatchEnddate varchar(15),
Intake_Capacity varchar(5))

Declare Batch_details_Cur Cursor for

		    select cbm.cbm_batch_id, Course_Name = (select top 1 ltrim(cmn_Minor_desc) from co_minor_master where cmn_minor_Code = cbm.cmn_minor_code), cbm.cmn_minor_Code, 
			Intake_Capacity = (select top 1 cbn_batch_nos from co_batch_number where cbm_batch_id=cbm.cbm_batch_id),			
			convert(char(12), cbm.cbm_batch_start_dt,106) as BatchStartdate, convert(char(12),cbm.cbm_batch_end_dt,106) as BatchEnddate, ltrim(cbm.Cbm_Batch_start_time)
			from co_batch_master cbm where cbm.cbm_active <> 'D' and datepart(year,cbm_batch_start_dt) <> '3000'
			and datepart(year,cbm_batch_start_dt) <> '4000'	and datepart(year,cbm_batch_start_dt) <> '5000' and datepart(year,cbm_batch_start_dt) <> '6000'
			and cbm.cmj_major_code = 'pstf' 
			and ((cbm_batch_start_dt between '03/03/2014' and '03/15/2014') or
			(cbm_batch_end_dt between '03/03/2014' and '03/15/2014'))
		    order by cbm.cmn_minor_Code, cbm.cbm_batch_start_dt

Open Batch_details_Cur
	fetch next from Batch_details_Cur into @BatchID, @MajorName, @Minorcode, @Intake_Capacity, @BatchStartdate, @BatchEnddate
	while @@Fetch_status = 0 
	begin

print @Intake_Capacity

insert into #TempTable values(@MajorName,@Minorcode,@BatchStartdate,@BatchEnddate,@Intake_Capacity)

		fetch next from Batch_details_Cur into @BatchID, @MajorName, @Minorcode, @Intake_Capacity, @BatchStartdate, @BatchEnddate
	end

close Batch_details_Cur
Deallocate Batch_details_Cur

select * from #TempTable
end




$ b当我跑步时,$ b

e存储过程显示错误如下






when i run the store procedure shows error as follows

exec [Presea_Intakerpts] 

Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.





我上面的商店程序有什么错误。



问候,

narasiman P.



what is the mistake in my above store procedure.

regards,
narasiman P.

推荐答案

你好,



你有一个额外的列 ltrim(cbm.Cbm_Batch_start_time)在SELECT查询中。删除它,错误就会消失。



问候,
Hello,

You have one extra column ltrim(cbm.Cbm_Batch_start_time) in your SELECT query. Remove it and the error should go away.

Regards,


cbm.cbm_batch_id,Course_Name,cbm.cmn_minor_Code,Intake_Capacity, BatchStartdate,BatchEnddate,ltrim(cbm.Cbm_Batch_start_time)

select查询中有七列,

游标声明下面的fetch语句中只有六个变量。





为Batch_Start_time添加新变量或删除select语句中的列。



希望这会有所帮助!!
cbm.cbm_batch_id, Course_Name , cbm.cmn_minor_Code,Intake_Capacity ,BatchStartdate,BatchEnddate, ltrim(cbm.Cbm_Batch_start_time)
There are seven columns in the select query and
there are only six variables in the fetch statement below the cursor declaration..


Either add a new variable for Batch_Start_time or remove the column in the select statement.

Hope this helps!!


这篇关于当我执行存储过程显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆