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
 Other Forums
 SQL Server 6.5 \ SQL Server 7.0
 SQL Cross Join

Author  Topic 

aharris
Starting Member

3 Posts

Posted - 2009-01-20 : 10:21:13
Hello, first post here. I have a question regarding SQL7. I have two tables, one called Orders, the other OrdItems. Only Orders contains the date field, which is OrderDate. I want to query OrdItems by using the associated date in Orders, as both tables DO contain field OrderNumber.
I feel that I am close with the following query string but need some help to figure out what I'm missing.

SELECT OrdItems.OrderNumber FROM Orders, OrdItems WHERE Orders.OrderDate="11/01/09'

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-20 : 10:28:32
What if you have two orders same day?
You better JOIN the two tables with OrderID or OrderNumber instead.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

aharris
Starting Member

3 Posts

Posted - 2009-01-20 : 10:42:29
Thanks! Could you help with the syntax? I basically want to get a data set from OrdItems based on a date range, but OrdItems does not have field OrderDate, table Orders does, and they both have OrderNumber, so I was hoping to create some type of relationship, but I've never used SQL joins before.

Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-20 : 11:51:00
SELECT o.*, oi.*
FROM Orders AS o
INNER JOIN OrdItems AS oi ON oi.OrderNumber = o.OrderNumber
WHERE o.OrderDate = '11/01/09'



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-20 : 12:02:54
quote:
Originally posted by aharris

Thanks! Could you help with the syntax? I basically want to get a data set from OrdItems based on a date range, but OrdItems does not have field OrderDate, table Orders does, and they both have OrderNumber, so I was hoping to create some type of relationship, but I've never used SQL joins before.

Thanks


and what should output when you've multiple order items present for same order
Go to Top of Page

aharris
Starting Member

3 Posts

Posted - 2009-01-20 : 12:37:48
Thanks to all that responded. Peso, that worked and I thank you for your help.
Go to Top of Page
   

- Advertisement -