Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a table Policy_details that has following structure -

policy_no int primary key,
tableno varchar(10),
term int,
sum_proposed int,
installment int,
p_dateback varchar(15),
issue_date varchar(15),
mode varchar(7)

I tried to get the date on which the installment will be due on the basis of the mode selected by user.Three types of modes are there Quarterly,Half Yearly and Yearly.

Here is my code -

create proc due_date
@pn int
as
begin
declare @tempdate datetime
declare @temp varchar(15)
declare @temp1 varchar(15)
declare @duedate datetime
declare @md varchar(7)
select @temp=issue_date,@temp1=p_dateback,@md=mode from Policy_details where policy_no=@pn
if @temp is null
set @tempdate=@temp1
else
set @tempdate=@temp
select Case @md
when Quarterly then select @duedate=DATEADD(month,3,@tempdate)
when Half Yearly then select @duedate=DATEADD(month,6,@tempdate)
when Yearly then select @duedate=DATEADD(month,12,@tempdate)
end as Due_Date
end

But this code is giving errors. Kindly help me solving those.Thank you
Posted

 
Share this answer
 
Replace
SQL
select Case @md
when Quarterly then select @duedate=DATEADD(month,3,@tempdate)
when Half Yearly then select @duedate=DATEADD(month,6,@tempdate) 
when Yearly then select @duedate=DATEADD(month,12,@tempdate)
end as Due_Date


with

SQL
SELECT @duedate = Case WHEN @md = 'Quarterly' then DATEADD(month,3,@tempdate)
WHEN @md= 'Half Yearly' then DATEADD(month,6,@tempdate)
WHEN @md= 'Yearly' then DATEADD(month,12,@tempdate)
END


NOTE:- Change @md varchar(7) to varchar(12)


Thank you
 
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