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
 General SQL Server Forums
 New to SQL Server Programming
 Generate Next Due Date in select Query

Author  Topic 

vinaym
Starting Member

8 Posts

Posted - 2011-01-24 : 10:43:27
I have table as following:
--Student
ID Name CertiDate
-------------------------
1 abc 01-01-2000
2 qwe 01-01-2009
3 asd 12-25-2010


I want output next due date of CertiDate which will be after 180 days. I am getting it through following query:

SELECT ID, Name, CertiDate, DATEADD(dd, 180, CertiDate) AS NextDueDate
FROM Student

but if NextDueDate is less than today's date then in NextDueDate I want Today's Date

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-24 : 10:48:40
you mean this?


SELECT ID, Name, CertiDate, CASE WHEN DATEADD(dd, 180, CertiDate) < GETDATE() THEN GETDATE() ELSE DATEADD(dd, 180, CertiDate) END AS NextDueDate
FROM Student


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vinaym
Starting Member

8 Posts

Posted - 2011-01-24 : 11:39:27
Yes Exactly....

Thanks visakh16
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-24 : 11:40:51
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -