Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / January 2007

Tip: Looking for answers? Try searching our database.

How do you find data in a range?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick Tipton - 24 Jan 2007 12:11 GMT
I have 2 tables. 1st has 2 fields that will be used to look up in another
table and retrieve a value in a range.

Table 1 fields - Name, Priority, Sales
Table 2 fields - Priority, Range, Contacts

Objective is based on the Priority and Sales from Table 1 will be used to
lookup in Table 2 the Priority and the maximum of Sales Range on Total Sales
should return a Contacts value.

Table 1 Data - Priority - 2, Sales - $200.00

Table 2 Data - Priority - 2, Range - $0, Contacts - 0
                    Priority - 2, Range - $150, Contacts - 2
                    Priority - 2, Range - $500, Contacts - 4
                    Priority - 2, Range - $1000, Contacts - 8

Should return Contacts = 4

I'm getting all rows above the expected value.

SELECT Table 1.Name, Table 1..Priority, Table 1.Sales, Table 2.Priority,
Table 2.Range, Max(Table 2.Range) AS MaxOfRange, Table 2.Contacts
FROM Table 1 INNER JOIN Table 2 ON Table 1.Priority = Table 2.Priority
GROUP BY Table 1.Name, Table 1.Priority, Table 1.Sales, Table 2.Priority,
Table 2.Range, Table 2.Contacts
HAVING (((Max(Table 2.Range))>=[Table 1]![Sales]));

Thank you for looking at this.
Stefan Hoffmann - 24 Jan 2007 13:30 GMT
hi Rick,

> I have 2 tables. 1st has 2 fields that will be used to look up in another
> table and retrieve a value in a range.

> Table 1 Data - Priority - 2, Sales - $200.00
>
[quoted text clipped - 4 lines]
>
> Should return Contacts = 4
You have an implicit range.

Using an explicit range it would be:

Table2: Data, Prio, RangeFromEx, RangeToInc, Contacts

SELECT T1.*, T2.*
FROM T1
INNER JOIN T2 ON T2.Prio = T1.Prio
AND T2.RangeFromEx > T1.Sales
AND T2.RangeToInc <= T1.Sales

> I'm getting all rows above the expected value.
> SELECT Table 1.Name, Table 1..Priority, Table 1.Sales, Table 2.Priority,
[quoted text clipped - 3 lines]
> Table 2.Range, Table 2.Contacts
> HAVING (((Max(Table 2.Range))>=[Table 1]![Sales]));

SELECT TOP 1 T1.*, T2.*
FROM T1
INNER JOIN T2 ON T2.Prio = T1.Prio
AND T2.Range > T1.Sales
ORDER BY T2.Range

mfG
--> stefan <--
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.