Solved

sql query help

Posted on 2009-06-30
2
324 Views
Last Modified: 2013-12-07
I have two tables to keep it simple they are ORDERS and ZONES, i have two parameters to pass to the query OrderRef and Zone, so if i have OrderRef = '123' and Zone = 'ONE' i only want results back from ORDERS table where BIN is in ZONE ONE,

ORDERS

OrderRef      Product      Bin      VALUE
123      ABC1      A      9.99
123      ABC2      B      12.99
123      ABC3      H      15.99
123      ABC4      C      4.99
123      ABC5      S      6.99

ZONES

ZONE      BINFROM      BINTO
ONE      A      C
TWO      D      J
THREE      K      Z

Desired Result is for OrderRef ='123' and Zone='ONE' is

OrderRef      Product      Bin      VALUE
123      ABC1      A      9.99
123      ABC2      B      12.99
123      ABC4      C      4.99

Result if OrderRef='123' and Zone='TWO' is
OrderRef      Product      Bin      VALUE
123      ABC3      H      15.99

I could do this with two queries but would like to build it into one,  
0
Comment
Question by:IanPaskin
2 Comments
 
LVL 25

Accepted Solution

by:
lwadwell earned 500 total points
ID: 24750030
Hi IanPaskin,

you could try something like ...

SELECT t2.OrderRef, t2.Product, t2.Bin, t2.VALUE
FROM zones t1
JOIN orders t2
ON t2.bin between t1.binfrom and t1.binto AND t2.orderref = '123'
WHERE t1.zone = 'ONE'

lwadwell
0
 
LVL 14

Expert Comment

by:shru_0409
ID: 24752041
select o.OrderRef,o.Product,o.Bin,o.VALUE
from orders o, ZONES z
where ascii(O.BIN) between ascii(z.BINFROM) and ascii(z.BINTO)
and z.zone = 'ONE'

this could help u
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now