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
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
When i exeucte the store procedure output as follows
Minorcode BatchStartdate BatchEnddate Intake_Capacity MajorName
DME 3-Mar-14 3-Mar-14 6 PSTF
GME 3-Mar-14 5-Mar-14 9 PSTF
Query as follows
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
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
in the above query i manually give date batch startdt and batch enddt as follows
((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
i want to set date as parameter in my above store procedure.
for that how can i do.
regards,
narasiman P.