473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Looking for a Creative Solution to a Group By Query problem.

At my company customers tend to change contracts in the middle of the
month. I need a query that will match 1 customer to 1 contract. If
the customer changes contracts before the 15th of the month, I want to
pick the 1st contract, but if he changes after the 15th I want to pick
the 2nd one. I have included sample data for 2 customers in Nov. My
query should pick records 2 and 3. I've been playing with if
statements in the Group By statement.
Customer Contract MonthMiddle ContractStart ContractEnd
888888 16663 11/15/2003 7/1/2003 11/26/2003
888888 16665 11/15/2003 11/27/2003 6/30/2006
777777 16663 11/15/2003 7/1/2003 11/12/2003
777777 16665 11/15/2003 11/13/2003 6/30/2006
Nov 12 '05 #1
1 1026
neptune wrote:
At my company customers tend to change contracts in the middle of the
month. I need a query that will match 1 customer to 1 contract. If
the customer changes contracts before the 15th of the month, I want to
pick the 1st contract, but if he changes after the 15th I want to pick
the 2nd one. I have included sample data for 2 customers in Nov. My
query should pick records 2 and 3. I've been playing with if
statements in the Group By statement.
Customer Contract MonthMiddle ContractStart ContractEnd
888888 16663 11/15/2003 7/1/2003 11/26/2003
888888 16665 11/15/2003 11/27/2003 6/30/2006
777777 16663 11/15/2003 7/1/2003 11/12/2003
777777 16665 11/15/2003 11/13/2003 6/30/2006


I have no idea what you are wanting to accomplish here. I suppose you
could attempt to set up an IIF() statement or some such method to set a
column to true or false...but I doubt that would help you in the long run.

If you are a programmer I suggest you create a function. I guess you
would pass the customer, contract, start, end, whatever to it. Then
process your data and return a True or False. Here is what your column
would look like in the query builder for calling the function.
UseThisRecord : CheckContract([Customer],[Contract],...)

Then your function, in a module, would be
Public Function CheckContract(varCustomer As Variant, _
varContract As Variant...) '... indicates other fields

Dim strSQL As String
Dim rst As Recordset
strSQL = your SQL Statement
set rst = currentdb.openrecordset(strSQL,...)

Now loop through the records in the recordset
and compare the values to the current record.
Pass back True or False whether this record
is to be displayed.
ENd Function

Basically, you want to compare all records for either that customer or
contract and see if there is a break. If not, then use it otherwise see
how the break is done and then return true/false based on the data.

If you don't know how to write a function you may be SOL.

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Angie | last post by:
Hello, My name is Angela Mastrodonato. I'm a web designer who would like the assistance of a php programmer. Some of my clients have requested more dynamic web sites, and I am in the beginning...
0
by: Gervas | last post by:
As you are all aware the Web has had a major impact on application architectures. In place of closed monolithic enterprise apps we are experienceing radical new developments in distributed...
3
by: Thomas R. Hummel | last post by:
Hi, I was just helping a coworker optimize a query. He had two versions: one which used UNION for each value for which he was tallying results and another query which used GROUP BY. Here is an...
1
by: TM | last post by:
My problem is a bit difficult to explain, having a relatively limited knowledge of .NET/C#, but please see if you can read between the lines. I have an ASPX that, on load, initiates a call to a...
4
by: Mick White | last post by:
mysql> select * from guestbook; +----+--------+---------+-----------------+----------------+ | id | fname | lname | comments | time_in |...
9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
3
by: Thats Me | last post by:
Task assigned is to assist in developing markup templates and rules for conversion of a group of technical manuals in MSWord from MIL-DTL-81928 to MIL-STD-3001. Am familiar with the basic concepts...
3
by: t8ntboy | last post by:
I have a table that contains a field for the start time for each day of the week (e.g., MondayStart, TuesdayStart, WednesdayStart, FridayStart, SaturdayStart, SundayStart). I need a query that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.