本文介绍了当我运行存储过程显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 USE [HIMT_Testing]GO/****** Object: StoredProcedure [dbo].[OH_Course_Elg] Script Date: 03/10/2015 15:51:29 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO ALTER Procedure [dbo].[OH_Course_Elg] @Studid varchar(100) as begin declare @Coursename varchar(100), @code varchar(100), @certificate varchar(100), @issueauth varchar(100), @issuedate varchar(100),@Cousrseelg Varchar(100) create table #Temptable (Coursename varchar(100)) create table #Temptable1 (code varchar(100), certificate varchar(100),issuseauth varchar(100),issuedate varchar(100)) begin tran declare coursename cursor for select distinct Course = case cr.cpm_pkg_id WHEN '' THEN cr.cmn_minor_code else cbm.cmn_minor_code end from course_registration cr, batch_course_registration bcr, co_batch_master cbm where 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_batch_start_dt > getdate() and datepart(year,cbm.cbm_batch_start_dt) <> '3000' and datepart(year,cbm.cbm_batch_start_dt) <> '4000' and datepart(year,cbm.cbm_batch_start_dt) <> '5000' and datepart(year,cbm.cbm_batch_start_dt) <> '6000' and cr.stud_id = @Studid open coursename fetch next from coursename into @Coursename while @@Fetch_status = 0 begin begin tran declare crselg cursor for select distinct a.pm_prof_code as Code,a.sp_cert_no as Certificate_No,a.sp_issu_authority as Issue_Authority, convert(char(14),a.sp_issu_dt,106) as Issue_Date, b.Courseelg as Cousrseelg from student_professional a,tb_courseelg_settings b where a.pm_prof_code= b.courseelg and b.coursename = @Coursename and a.stud_id = @studid order by Issue_Date desc --print 'inside' open crselg fetch next from crselg into @code,@certificate,@issueauth,@issuedate,@Cousrseelg while @@Fetch_status = 0 begin insert into #Temptable values(@Coursename) insert into #Temptable1 values (@code,@certificate,@issueauth,@issuedate) fetch next from crselg into @code,@certificate,@issueauth,@issuedate,@Cousrseelg end close crselg deallocate crselg commit tran fetch next from coursename into @Coursename end close coursename deallocate coursename commit transelect * from #Temptableendselect * from #Temptable1end 当我运行上面的商店程序时显示错误如下 'end'附近的语法不正确。 我的问题是什么商店程序。 问候, Narasiman P. 添加了代码块 - OriginalGriff [/ edit] When i run the above store procedure shows error as followsIncorrect syntax near 'end'.What is the problem in my store procedure.Regards,Narasiman P.[edit]Code block added - OriginalGriff[/edit]推荐答案 Create Procedure [dbo].[OH_Course_Elg] @Studid varchar(100) as begin declare @Coursename varchar(100), @code varchar(100), @certificate varchar(100), @issueauth varchar(100), @issuedate varchar(100),@Cousrseelg Varchar(100) create table #Temptable (Coursename varchar(100)) create table #Temptable1 (code varchar(100), certificate varchar(100),issuseauth varchar(100),issuedate varchar(100)) begin tran declare coursename cursor for select distinct Course = case cr.cpm_pkg_id WHEN '' THEN cr.cmn_minor_code else cbm.cmn_minor_code end from course_registration cr, batch_course_registration bcr, co_batch_master cbm where 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_batch_start_dt > getdate() and datepart(year,cbm.cbm_batch_start_dt) <> '3000' and datepart(year,cbm.cbm_batch_start_dt) <> '4000' and datepart(year,cbm.cbm_batch_start_dt) <> '5000' and datepart(year,cbm.cbm_batch_start_dt) <> '6000' and cr.stud_id = @Studid open coursename fetch next from coursename into @Coursename while @@Fetch_status = 0 begin begin tran declare crselg cursor for select distinct a.pm_prof_code as Code,a.sp_cert_no as Certificate_No,a.sp_issu_authority as Issue_Authority, convert(char(14),a.sp_issu_dt,106) as Issue_Date, b.Courseelg as Cousrseelg from student_professional a,tb_courseelg_settings b where a.pm_prof_code= b.courseelg and b.coursename = @Coursename and a.stud_id = @studid order by Issue_Date desc --print 'inside' open crselg fetch next from crselg into @code,@certificate,@issueauth,@issuedate,@Cousrseelg while @@Fetch_status = 0 begin insert into #Temptable values(@Coursename) insert into #Temptable1 values (@code,@certificate,@issueauth,@issuedate) fetch next from crselg into @code,@certificate,@issueauth,@issuedate,@Cousrseelg end close crselg deallocate crselg commit tran fetch next from coursename into @Coursename end close coursename deallocate coursename commit transelect * from #Temptableselect * from #Temptable1end 您的陈述: Your statements:select * from #Temptableend (at here the begin will be closed so that's why it's giving error for next end).select * from #Temptable1end 这篇关于当我运行存储过程显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-23 18:53