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 |
rookie_sql
Constraint Violating Yak Guru
443 Posts |
Posted - 2007-10-08 : 06:38:28
|
Hi when i run this script i get my data returned select *from tbl_orderswhere orderdate = '05/10/2007'orderdate datatype = datetime I want to extract data from another data source on another database, when i run this script on it i get no data backselect *from orders where orderdate >= getdate() -3orderdate datatype = datetime Does any1 know why i can't return the data |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-08 : 06:42:51
|
getdate() brings date as well as time with it which may be causing comparison to fail. Also GetDate() returns date and time on the server.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-08 : 06:54:12
|
quote: Originally posted by rookie_sql select *from orders where >= getdate() -3
You must compare the right side of the >= with a valid left side.select *from orders where orderdate >= getdate() -3orselect *from orders where orderdate >= DAteadd(day, datediff(day, 3, getdate()), 0) E 12°55'05.25"N 56°04'39.16" |
 |
|
rookie_sql
Constraint Violating Yak Guru
443 Posts |
Posted - 2007-10-08 : 07:03:44
|
Is there any way around it i would like to use the getdate() - 3 if possible as i need to run this job each week. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-08 : 07:05:37
|
Did you try the two suggestions in my previous post? E 12°55'05.25"N 56°04'39.16" |
 |
|
rookie_sql
Constraint Violating Yak Guru
443 Posts |
Posted - 2007-10-08 : 07:13:15
|
Sorry that was a mistake in my post i was missing the where orderdate >= getdate() - 3i tried where orderdate >= Dateadd(day, datediff(day, 3, getdate()), 0)and i get no data returned, i just tested this and it worked for the pervious day , it bring me back data for last thursday but i know there is data for friday when i hard code the date select *from orders where orderdate >= getdate() -4 |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-10-08 : 08:17:55
|
"it bring me back data for last thursday"Was it already Monday in your timezone? Because if it was you should NOT have got data for Thursday!(But I agree you should have got data for Friday, unless your timezone is already Tuesday )Kristen |
 |
|
|
|
|
|
|