May 19, 2010 at 1:09 pm
Afternoon,
Trying to use an if statement to return a date plus 3 months If I take out the th if statement then returns fine but I wast to use the check box.
declare @checkbox char(1)
declare @DisplayDate varchar(80)
declare @sd datetime
set @checkbox = (select att1 from pdt_first_time_homebuyers_Club_View where client_id = @client_id and pd_id = @pd_id)
set @DisplayDate = (select atdate1 from pdt_first_time_homebuyers_Club_View where client_id = @client_id and pd_id = @pd_id)
if @checkbox = 1
begin
select @sd
set @displayDate = dateadd(mm,3, @sd) --(CONVERT(varchar(50),dateadd(mm,3,@sd),101))
end
select coalesce (@displaydate,'')
May 19, 2010 at 1:30 pm
I suspect you're failing your if test. Check the value of your variables:
set @checkbox = (select att1 from pdt_first_time_homebuyers_Club_View where client_id = @client_id and pd_id = @pd_id)
select @checkbox [@checkbox], @Client_id [@Client_id], @pd_id [@pd_id]
May 19, 2010 at 3:16 pm
Where do you assign any value to @sd?
_____________
Code for TallyGenerator
May 19, 2010 at 3:25 pm
And it should be all in one SELECT statement:
select CASE WHEN att1 = 1 THEN CONVERT(varchar(50), dateadd (mm, 3, @sd ), 101)
ELSE atdate1
END displayDate
FROM pdt_first_time_homebuyers_Club_View
where client_id = @client_id and pd_id = @pd_id
_____________
Code for TallyGenerator
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply