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 / Queries / May 2005

Tip: Looking for answers? Try searching our database.

Help with a query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael D. - 18 May 2005 14:19 GMT
I have this database structure:

GroupNumber  GN End Range    GroupName    CustServInd
7404            Don and Deb Lawyer          A
7405            Don and Deb Lawyer          A
7406            Don and Deb Lawyer           A
8683            Central Hardware Service   A
8684            Central Hardware Service   A
7616            Chemical Company HQ       A
9528            Wild Workout Center         A
0407            Wild Workout Center         A
8219            Wood Mill                  A
8764            Don and Deb Lawyer         A
   

TheGN End Range field is to be populated with the maximum GroupNumber for a
group, where a group is a unique GroupNumber and GroupName combo, AND THE
GroupNumber's are in SEQUENCE.  The Group Number End Range is only to be
filled when there is more than 1 GroupNumber for a group.  Thus, when the
module is complete, the above record set should look like this:

GroupNumber  GN End Range   GroupName                     CustServInd
7404            7406            Don and Deb Lawyer               A
8683            8684            Central Hardware Service        A
7616                   Chemical Company HQ            A
9528                   Wild Workout Center               A
0407                   Wild Workout Center               A
8219                   Wood Mill                    A
8764                   Don and Deb Lawyer              A

The query I have below fills in Group Number End Range for Don and Deb
Lawyer as 8764, but this is incorrect, as it is not in sequence.  Another
example would be Wild Workout Center.  My query groups them as one, with an
end range of 0407.  but they should be treated as separate groups, since the
numbers are not in sequence.

SELECT Min([GroupNumber]) AS MinGroupNumber,
IIf(Max([GroupNumber])>Min([GroupNumber]),Max([GroupNumber]),Null) AS
MaxGroupNumber, GroupName, CustSvcInd
FROM tblGroups
GROUP BY CustSvcInd, GroupName
ORDER BY CustSvcInd, Min(Groups.GroupNumber);

Hopefully this all makes sense!  I really need to take an sql class, I know
bits and pieces but that's it...
Gary Walter - 20 May 2005 14:14 GMT
>I have this database structure:
>
[quoted text clipped - 40 lines]
> GROUP BY CustSvcInd, GroupName
> ORDER BY CustSvcInd, Min(Groups.GroupNumber);

Hi Michael,

Simple example:
("Num" is type Number in below table)

tblMicheal:

Num    Grp
7404    D
7405    D
7406    D
8683    C
8684    C
8764    D

qryMichael:

SELECT
t.Num, t.Grp,
[Num]+1 AS NextNum,
Exists (SELECT A.Num FROM tblMichael As A
WHERE A.Num=t.Num +1 AND A.Grp=t.Grp) AS NextNumExists
FROM tblMichael AS t;

gives:

Num    Grp  NextNum    NextNumExists
7404    D    7405            -1
7405    D    7406            -1
7406    D    7407            0
8683    C    8684           -1
8684    C    8685            0
8764    D    8765            0

query to get what I think you want:

SELECT
t1.Num,
t1.Grp,
(SELECT Min(Q.Num) FROM qryMichael As Q
WHERE Q.Num>=t1.Num
AND Q.Grp=t1.Grp
AND Q.NextNumExists=0) AS EndRange
FROM tblMichael AS t1;

Num    Grp  EndRange
7404    D     7406
7405    D     7406
7406    D     7406
8683    C     8684
8684    C     8684
8764    D     8764

All that's left would be to convert to UPDATE qry.

Good Luck,

gary
Gary Walter - 20 May 2005 15:04 GMT
Just one more thought...

I am not sure I would store
this "EndOfRange" in a table.
It is something that can always
be "calculated" for current data.

gary
 
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.