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)
 spliting duedate and non duedate

Author  Topic 

ntn104
Posting Yak Master

175 Posts

Posted - 2008-08-15 : 09:41:18
Hi All,

I would like to split my duedate column into two categories: "NON DUE DATE' AND "PAST DUE DATE". I wonder if anyone can help...Thanks,

here is sample of Duedate data:
Due Date



2006-12-21-00.00.00.000000

2008-10-09-00.00.00.000000

2006-12-21-00.00.00.000000

2008-06-16-00.00.00.000000

2008-08-28-00.00.00.000000

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-08-15 : 09:42:47
?? what constitues a 'non due date' or 'past due date'?

Em
Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2008-08-15 : 09:45:49
quote:
Originally posted by elancaster

?? what constitues a 'non due date' or 'past due date'?

Em



i am thinking to compare duedate with today date like
case when duedate>=getdate()then 'Not Due Yet'
else 'Past Due Date'

Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-08-15 : 09:53:09
that seems fine other than be aware that getdate() has the time as well so your case may not work. use...
dateadd(day,datediff(day,0,getdate()),0) instead


Em
Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2008-08-15 : 10:02:46
quote:
Originally posted by elancaster

that seems fine other than be aware that getdate() has the time as well so your case may not work. use...
dateadd(day,datediff(day,0,getdate()),0) instead


Em



Thank you for your input. Both cases are work very well. But I prefer to use your.

Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-08-15 : 10:06:17
the reason i suggest it is...

in your table... 2008-08-15 00:00:00.000
and getdate() gives... 2008-08-15 15:04:37.997

in your query when you say duedate >= getdate() it will not find those listed for today. by stripping getdate() back to midnight you ensure you match your record in the table

Em
Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2008-08-15 : 10:24:33
quote:
Originally posted by elancaster

the reason i suggest it is...

in your table... 2008-08-15 00:00:00.000
and getdate() gives... 2008-08-15 15:04:37.997

in your query when you say duedate >= getdate() it will not find those listed for today. by stripping getdate() back to midnight you ensure you match your record in the table

Em



Thanks for your explaination...That 's really help me to understand the different between two methods.
Cheers,
Go to Top of Page
   

- Advertisement -