narasiman rao

narasiman rao

  • NA
  • 519
  • 769.1k

My store procedure is not working

Mar 12 2015 6:19 AM
  My store procedure as follows
 
 
USE [HIMT_Testing]
GO
/****** Object: StoredProcedure [dbo].[OH_Course_Elg] Script Date: 03/10/2015 15:51:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
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 tran
select * from #Temptable
end
select * from #Temptable1
end
When i run the above store procedure shows error as follows
Incorrect syntax near 'end'.

What is the problem in my store procedure.

Regards,
Narasiman P. 
 

Answers (1)