Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Nested if causeing problem

Author  Topic 

scottichrosaviakosmos
Yak Posting Veteran

66 Posts

Posted - 2010-07-03 : 07:25:23
i have a procedure and i want to check whether the date entered by user should not be greater then current day and not less then 3 years
so i am checking year month and days by matching with IF statement.
now when i m trying to run then i m getting error of nesting of if .
Important thing is that i also have to check leap year. anf if leap year then check the condition according to that . but i m getting error because of if satatement.
can anyone help. and send me corrent method.
the SQL sode is below.:

create proc finddatediffnew
@enddate DATETIME,
@Startdate DATETIME
as
--DECLARE @EnterDate DATETIME
--DECLARE @CurrentDate DATETIME
declare @Eyear int
set @Eyear=year(@enddate )
declare @Cyear int
set @cyear=year(@Startdate)
--SET @EnterDate = '20070902'
--SET @EnterDate = '2008/7/8'

--SET @CurrentDate = GETDATE()

if((@Eyear/4)=0 and (@Cyear/4)=0)

SELECT
CASE
WHEN @enddate BETWEEN DATEADD(YEAR, -3, @Startdate) AND @Startdate
THEN '0'--'valid'
ELSE '1'--'not valid'




else

SELECT
CASE
WHEN @enddate BETWEEN DATEADD(YEAR, -3, @Startdate) AND @Startdate
THEN '0'--'valid'
ELSE '1'--'not valid'








scoo

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-03 : 08:56:47
you missed the END after the CASE WHEN . . THEN .. ELSE .. END


SELECT
CASE
WHEN @enddate BETWEEN DATEADD(YEAR, -3, @Startdate) AND @Startdate
THEN '0'--'valid'
ELSE '1'--'not valid'
END



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -