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.
| 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.0000002008-10-09-00.00.00.0000002006-12-21-00.00.00.0000002008-06-16-00.00.00.0000002008-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 |
 |
|
|
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' |
 |
|
|
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) insteadEm |
 |
|
|
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) insteadEm
Thank you for your input. Both cases are work very well. But I prefer to use your. |
 |
|
|
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.000and getdate() gives... 2008-08-15 15:04:37.997in 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 tableEm |
 |
|
|
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.000and getdate() gives... 2008-08-15 15:04:37.997in 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 tableEm
Thanks for your explaination...That 's really help me to understand the different between two methods.Cheers, |
 |
|
|
|
|
|