473,789 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access assistance, if you can. Query related.

56 New Member
Hi,

I wondered if you could help me with an issue I'm having. Currently I have a rebate calculation that is running off two tables:

1) A list of suppliers and the rebate %ages relevant to them
2) A ongoing list of invoice details, including a month/year period and an invoice total

At the moment, I can happily run the rebate calculation for the current month. What I would like to do is begin to track changes in supplier rebate rates over time. This means applying a month/year period for the date which the rebate is applicable against each line entered on the rebate table.

The theory is that when I run my query, it goes in, finds the correct rebate rate to apply from a specifed period and then calculates based on those rates. This means I can track changes, but also run the calc historically if necessary (which is the end purpose of my calc).

The problem I'm having is, no matter what I enter in my query, it seems determined to give results for each and every line that exists in the supplier rebate table, regardless of the date that is against that line.

For example, I can have data that is like:

Supplier A - 2% - 2007-03
Supplier A - 3% - 2007-08
Supplier A - 5% - 2008-01

on the rebate table. If I run a calc with a run date of 2007-10, I want it to go and pull off all the October 2007 rebates, and then use the rebate rate of 3% against it. At the moment it gives me results for 2%, 3% and 5%, a record for each.

If this doesn't make sense, I could expand further!

My existing query is this if you find it useful:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT Rebates_Supplier.ClientNumber, Rebates_Supplier.Name AS Supp, Rebates_Supplier.Group, Sum([Rebates_CBS Transaction Data]![Base Amount]*-1) AS [Gross Amount], Sum(([Rebates_CBS Transaction Data]![Base Amount]*-1)*Rebates_Supplier!CBSRebateAmt/100) AS CBS, Sum(([Rebates_CBS Transaction Data]![Base Amount]*-1)*Rebates_Supplier!PfHRebateAmt/100) AS PfH, Sum(([Rebates_CBS Transaction Data]![Base Amount]*-1)*Rebates_Supplier!TotalRebate/100) AS Total, [Rebates_CBS Transaction Data].[Rebate Date], Rebates_Supplier.Category, Rebates_Supplier.Status, Rebates_Supplier.CBSRebateAmt, Rebates_Supplier.PfHRebateAmt, Rebates_Supplier.Frequency
  3.  
  4. FROM Rebates_Supplier INNER JOIN [Rebates_CBS Transaction Data] ON Rebates_Supplier.Name = [Rebates_CBS Transaction Data].Name
  5.  
  6. GROUP BY Rebates_Supplier.ClientNumber, Rebates_Supplier.Name, Rebates_Supplier.Group, [Rebates_CBS Transaction Data].[Rebate Date], Rebates_Supplier.Category, Rebates_Supplier.Status, Rebates_Supplier.CBSRebateAmt, Rebates_Supplier.PfHRebateAmt, Rebates_Supplier.Frequency, Rebates_Supplier.Category
  7.  
  8. HAVING (((Rebates_Supplier.ClientNumber)>0) AND (([Rebates_CBS Transaction Data].[Rebate Date])="2007-08") AND ((Rebates_Supplier.Category)="C") AND ((Rebates_Supplier.Status)="Active") AND ((Rebates_Supplier.Frequency)="Monthly"));
  9.  
  10.  
Feb 4 '08 #1
15 2015
Rabbit
12,516 Recognized Expert Moderator MVP
You're going to need to use a subquery to return only one record from the rebates table per record in your invoice table.
Feb 5 '08 #2
Widge
56 New Member
Crikey, not used subqueries before. I'll see if I can find any guides.
Feb 6 '08 #3
Widge
56 New Member
Oh what am I talking about I've used a subquery before. Ok, I have a slight advancement on this problem. I'm using this query in VBA as part of a ADODB.Recordset . What I currently do is set a string full of my SQL from the query, including some sections where there is user input from a form, and have it run. How would I use a subquery in this instance?

Instead of referring to my tables, can I refer to a query instead?
Feb 6 '08 #4
Widge
56 New Member
Actually I'm still a bit baffled at how to structure the query to pick out the applicable date across all suppliers. I'm basically asking it to pick off all records BEFORE the entered date. Now I pick up all the supplier rebate rates previous to that date, including any historical ones if there are any. I can't figure out how to strip out these historical ones.
Feb 6 '08 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Well, a quick and dirty example of this would be:
Expand|Select|Wrap|Line Numbers
  1. SELECT (SELECT TOP 1 RebatePct FROM tblRebate WHERE x.PurchaseDate > RebateDate ORDER BY RebateDate DESC) AS RebatePercent, PurchaseDate, Vendor
  2. FROM tblPurchases AS x;
  3.  
Of course this only uses a date as the determining factor for the rebate amount. Your criteria may be more complex and all of that can be built into the query.
Feb 6 '08 #6
Widge
56 New Member
Well, a quick and dirty example of this would be:
Expand|Select|Wrap|Line Numbers
  1. SELECT (SELECT TOP 1 RebatePct FROM tblRebate WHERE x.PurchaseDate > RebateDate ORDER BY RebateDate DESC) AS RebatePercent, PurchaseDate, Vendor
  2. FROM tblPurchases AS x;
  3.  
Of course this only uses a date as the determining factor for the rebate amount. Your criteria may be more complex and all of that can be built into the query.
Had a go.... gave me the same percentage all the way down for each supplier.

Was this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT Rebates_Supplier.Name AS Supp, (SELECT TOP 1 Rebates_Supplier.TotalRebate From Rebates_Supplier WHERE [Rebates_CBS Transaction Data].[Rebate Date] > Rebates_Supplier.DateApplied ORDER  BY Rebates_Supplier.DateApplied Desc) , [Rebates_CBS Transaction Data].[Rebate Date]
  3. FROM Rebates_Supplier INNER JOIN [Rebates_CBS Transaction Data] ON Rebates_Supplier.Name = [Rebates_CBS Transaction Data].Name
  4. GROUP BY Rebates_Supplier.Name, Rebates_Supplier.TotalRebate, [Rebates_CBS Transaction Data].[Rebate Date]
  5. HAVING ((([Rebates_CBS Transaction Data].[Rebate Date])="2007-08"));
  6.  
  7.  
just doing a tester to see if it would work. I could knock up a test DB with my data (I'll have to edit out names and stuff) to demonstrate?

Cheers for being on hand btw!
Feb 8 '08 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Of course you have the same percent all the way down, every transaction has the same date.
Feb 8 '08 #8
Widge
56 New Member
Right, this should help visualise it:

http://www.sendspace.c om/file/janqm7

Thats an example. Usually the database is full of months and months of transaction data, plus the rebates table is full of suppliers.

What I've put in is an example of how I want the history of rebate rates to flow. SuppB has had a good few different rates over time.

I want to be able to run the query and have SuppB only display a result for the relevant date that its rebate rate is applicable for.

For the 2007-08 period, Supp B should be calculated on the 3% rate, my query is creating a line for every single historical rate. I can't find a way to make it pick off the correct one. I need to make sure that each time the query pulls off across all suppliers, the correct period. Such as Supp A only has one line of entry which is valid from 2006, that must be used across all Supp A's. If I ran a calc at 2008-01 then Supp B would have a different rate, but Supp A would still stay the same because its still valid from 2006 with no change.

What happens is this data will then populate a table on a form (which can be copied and pasted)... then I have a piece of code that uses the results of this to go and autopopulate rebate invoices. In its current form, it would create 3 Supp B invoices when run for 2007-08, with only one actually being correct.
Feb 11 '08 #9
Widge
56 New Member
A better and less complex version of my database for example:

For download here is my database. Inside are two table and query set,
one set which is running of my current spec where I don't use any
historical records.... runs fine. One where it is running using
historical entries for SuppB (as an example), as you can see when
running the query, 3 lines for SuppB show. I need the relevant one to
display only for Supp B.

Also I have to make sure the likes of Supp A are not affected.

Thanks for any help!

Database:

http://www.sendspace.c om/file/nxjko3
Feb 11 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
7558
by: deko | last post by:
From what I understand, an Inner Join narrow the rows selected to the table with the least results... and an Outer Join does the opposite... SELECT qryTxToQ1.Q1Total, qryTxToQ2.Q2Total, qryTxToQ3.Q3Total, qryTxToQ4.Q4Total FROM qryTxToQ4 OUTER JOIN (qryTxToQ3 OUTER JOIN (qryTxToQ1 OUTER JOIN qryTxToQ2 ON qryTxToQ1.TxAcct_ID = qryTxToQ2.TxAcct_ID) ON qryTxToQ3.TxAcct_ID = qryTxToQ2.TxAcct_ID) ON qryTxToQ4.TxAcct_ID = qryTxToQ3.TxAcct_ID;
2
14936
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data in the format that I need it in order to create the reports that we use. So far this has proven to be successful for the reports that I am doing and the data that I am pulling into it. I just have one challenge that may require a lot of work and I...
1
4178
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
2
5017
by: SenseForAll | last post by:
First please note I am a novice at VBA and not even that experienced with DAO/ADO and MS-SQL. Any assistance is appreciated. That said... I have an application written in Access w/ VBA. I need to get some data out of a SQL server and into an Access table. I don't know anything about the SQL server data model or structure. I don't have access rights to link to the SQL table. What I do have is the rights and information to run a stored...
0
2024
by: Rolan | last post by:
I know what I want to do regarding the average cost for inventory, but need some assistance to sort out some of the details to finalize an inventory table and query. Essentially, the information is needed for year end reporting and not for on-going review. Below is an example that summarizes it all. tblMain/frmMain /IDTag tblPurchases/sfrmPurchases/IDPur/PurCost/UnitsPur tblSales/sfrmSales/IDSales/UnitsSold
5
2768
by: Bob Alston | last post by:
I am looking for any Microsoft Access based software that could be used for a United Way agency that provides basic needs assistance - food, clothing, financial (rent, utilities, Rx, gasoline, etc). Preferably free. Definitely with source code as we would most likely want to customize it. Are you aware of such? Bob
2
1542
by: Jan Szymczuk | last post by:
Thanks again guys, for your recent assistance. Now as you were so kind to assist the first time (the solution was so simple and elegant) I was wondering if you could assist with another couple of problems I am faced with. Problem 1 I have a memo field called NOTES in my database and I have constructed various queries so the user can search this NOTES memo field for any freetext held within it. As this memo field has large chunks of text...
52
9989
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server 2005, and, since he already has licenses for Office Pro 2002, he wants to upgrade to that. I've been saying that we need to upgrade to Access 2003, not 2002, even if Office is kept at 2002. We are also looking to do a fair amount of...
3
2260
by: gaurav92K | last post by:
sir i am working in a company . there are many pc. i want to use remote assistance. i configure all group policy which are related remote assistance.and i enable service through remote in system property.every services related remote desktop & remote assistance are start . but i can not use help assistance through another system while i try help assistance in my pc then help assistance begin start. what is problem please give the best answer on...
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.