Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

SQL 2000 problems...

Thread Tools
 
Search this Thread
 
Old 30 January 2003, 12:55 PM
  #1  
MrDeference
Scooby Regular
Thread Starter
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

SQL Question.

Having a bit of a mare with GetDate().

Can anyone explain why :
SELECT OrderHeader.orderUID, OrderHeader.orderDate FROM OrderHeader INNER JOIN OrderSubItem ON OrderHeader.orderUID = OrderSubItem.orderUID WHERE 60 > DATEDIFF(mi, OrderHeader.orderDate, GETDATE())

would return nothing, whereas the same without the JOIN does. i.e.

SELECT OrderHeader.orderUID, OrderHeader.orderDate FROM OrderHeader WHERE 60 > DATEDIFF(mi, OrderHeader.orderDate, GETDATE())


The join clause is valid, such that the first statement with out the WHERE clause will return data.

The object names and column names have been conjured up to convey meaning, so critical analysis of the table structure or pointing out the uselessness of the join will be ignored , cheers

Another thing. I have an app that is tipping entries into the database about once every 2 seconds. This has been running for 4 days. The timestamp on the entry (generated with GetDate() in the SQL string, rather than through the default entry) is now 9 hours in advance of system time.

Any one got any ideas what is going on?
MS SQL Server 2000, SP3 on XP.
Cheers.
Old 30 January 2003, 10:09 PM
  #2  
MrDeference
Scooby Regular
Thread Starter
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

So, thanks to those 35 or so people that had a look.

The answer is:
SELECT OrderHeader.orderUID, OrderHeader.orderDate FROM OrderHeader INNER JOIN OrderSubItem ON OrderHeader.orderUID = OrderSubItem.orderUID WHERE 60 > DATEDIFF(mi, OrderHeader.orderDate, GETDATE())

should read:

SELECT OrderHeader.orderUID, OrderHeader.orderDate FROM OrderHeader INNER JOIN OrderSubItem ON OrderHeader.orderUID = OrderSubItem.orderUID AND 60 > DATEDIFF(mi, OrderHeader.orderDate, GETDATE())

Anyone who can tell me *why* changing from WHERE to AND makes the blindest bit of difference wins my eternal respect.
Cheers.
Old 30 January 2003, 10:16 PM
  #3  
Fosters
Scooby Regular
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
Post

the where is outside the join, whereas the and is tightening the join criteria.
Old 30 January 2003, 10:56 PM
  #4  
MrDeference
Scooby Regular
Thread Starter
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

Fosters,
Cheers very much for the reply. I am not sure I understand it though...
If the JOIN criterion is already met, tightening it up after the JOIN should make no difference to the resultant dataset.
If you follow?
What is wrong with my thinking?
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
S600HBY
Subaru Parts
8
03 October 2015 05:14 PM
Lillyart14
ScoobyNet General
24
01 October 2015 01:29 AM
buckerz69
Wanted
2
29 September 2015 02:58 PM
madmover
Member's Gallery
4
28 September 2015 10:46 AM



Quick Reply: SQL 2000 problems...



All times are GMT +1. The time now is 07:51 PM.