Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

Use Operators instead of between
CONVERT(varchar,cbm_batch_start_dt,101)> = CONVERT(varchar,StartDate,101) and CONVERT(varchar,cbm_batch_end_dt ,101) <= CONVERT(varchar,EndDate,101)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900