Author |
Topic |
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2006-12-21 : 05:45:58
|
Here's my sp. It is deleting records with today's date - why isn't'and tblFileRequests.DateRequested < getdate()' working ????CREATE PROCEDURE [spRMU_DeleteBlankRequests] ASDELETE tblFileRequestsFROM tblFileRequestsLEFT JOIN tblFileRequestDetails ON tblFileRequests.MovementId = tblFileRequestDetails.MovementIdWHERE tblFileRequestDetails.MovementId Is Nulland tblFileRequests.DateRequested < getdate()GO |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-21 : 05:49:15
|
1) Which datatype is column DateRequested?2) GETDATE() also returns millisecondsCREATE PROCEDURE [spRMU_DeleteBlankRequests]ASDELETE tblFileRequestsFROM tblFileRequestsLEFT JOIN tblFileRequestDetails ON tblFileRequests.MovementId = tblFileRequestDetails.MovementIdWHERE tblFileRequestDetails.MovementId Is Nulland tblFileRequests.DateRequested < dateadd(day, datediff(day, 0, getdate()), 0) Peter LarssonHelsingborg, Sweden |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-12-21 : 05:49:29
|
What is the datatype for DateRequested? Varchar or Datetime?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2006-12-21 : 05:50:40
|
You must remember that getdate() returns datetime - which has a time attached to it too.So if you are storing your data with a midnight time and the time now is say 12:52:00 then all of the midnight times and everything up to 12:51:59 for todays date and dates before today will be deleted.Duane. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-21 : 05:53:31
|
Peter LarssonHelsingborg, Sweden |
 |
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2006-12-21 : 05:54:49
|
DateRequested is Datetime |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-21 : 05:57:17
|
Shiver... I feel we now enter Twilight Zone where OP does not read answers.Pinto, try the query I suggested above.Peter LarssonHelsingborg, Sweden |
 |
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2006-12-21 : 05:57:21
|
Thanks peso, < dateadd(day, datediff(day, 0, getdate()), 0) is working fine now. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-21 : 06:00:40
|
It is the DATEDIFF function that truncates time information by calculating whole days passed since January 1, 1900 (or days left until January 1, 1900).And then DATEADD add the day difference to January 1, 1900 to get back to today's date, without time information.Well, this is not entirely true. Time is midnight (00:00:00) or 12 pm for our american friends.Peter LarssonHelsingborg, Sweden |
 |
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2006-12-21 : 06:09:26
|
Thanks for the explanation, Peso. I was only storing the date in my table. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-21 : 07:19:16
|
More on dateswww.sql-server-performaqnce.com/fk_datetime.aspMadhivananFailing to plan is Planning to fail |
 |
|
KenW
Constraint Violating Yak Guru
391 Posts |
Posted - 2006-12-22 : 15:19:51
|
quote: Originally posted by Pinto Thanks for the explanation, Peso. I was only storing the date in my table.
Not with a DateTime column, you weren't. For a DateTime column, SQL server stores both the date and time. If you don't supply a time value, it uses 12:00:00am. So, one way or the other, you're storing both date and time.Ken |
 |
|
|