473,406 Members | 2,387 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,406 software developers and data experts.

Query translate from MySQL to Access

6
Hi!!

I am becoming crazy trying to pass a sentence from MySQL to Access.

The issue is as follows:

I have one table (BoQ) with codes (Cod) and quantities (Q) and another table (BD) with codes (Cod) and invoices (Sub).

I want a query that gives me one line for each code, containing the code, the sum of all quantities for the code and the sum of all invoices for the code.

I have written the following MySQL sentence that looks like working:

select
B.Cod, sum(B.q) as Quan, if(isnull(J.Cost),0,J.Cost) as Rate,
if(isnull(sum(B.q) * j.Cost),0,sum(B.q) * j.Cost) As Cost
from BoQ AS B
left join (
SELECT Cod, sum(Sub) Cost
FROM BD GROUP BY BD.Cod) AS J
on b.Cod = j.Cod GROUP BY B.Cod;

The query looks like working .... but it absolutelly looks like I am unable to translate it to access.

May anyone help me with that??

Thank you so much in advance!!!
Feb 27 '17 #1

✓ answered by jforbes

When using the GROUP BY keyword, any field in the SELECT portion for the statement needs to be accounted for either in the GROUP BY or with an Aggregate Function. Neither Rate nor Cost are an Aggregate or in the GROUP BY.

You've also got an IF() function, which should probably be IIF() function. or use a NZ() function if you are looking to provide a Zero instead of a Null

From what it looks like your attempting, you will probably need to include another SubQuery or reorder the query to only have one GROUP BY. This might work, I have my doubts, but it should get you closer:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.   B.Cod
  3. , NZ(J.Quan,0) AS Quan
  4. , NZ(J.Cost,0) AS Rate
  5. , NZ(J.Quan * j.Cost,0) AS Cost
  6. FROM BoQ AS B
  7. LEFT JOIN (
  8.   SELECT 
  9.     Cod
  10.   , SUM(Sub) AS Cost
  11.   , SUM(B.q) AS Quan
  12.   FROM BD 
  13.   GROUP BY BD.Cod) AS J
  14. ON b.Cod = j.Cod  

2 1670
jforbes
1,107 Expert 1GB
When using the GROUP BY keyword, any field in the SELECT portion for the statement needs to be accounted for either in the GROUP BY or with an Aggregate Function. Neither Rate nor Cost are an Aggregate or in the GROUP BY.

You've also got an IF() function, which should probably be IIF() function. or use a NZ() function if you are looking to provide a Zero instead of a Null

From what it looks like your attempting, you will probably need to include another SubQuery or reorder the query to only have one GROUP BY. This might work, I have my doubts, but it should get you closer:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.   B.Cod
  3. , NZ(J.Quan,0) AS Quan
  4. , NZ(J.Cost,0) AS Rate
  5. , NZ(J.Quan * j.Cost,0) AS Cost
  6. FROM BoQ AS B
  7. LEFT JOIN (
  8.   SELECT 
  9.     Cod
  10.   , SUM(Sub) AS Cost
  11.   , SUM(B.q) AS Quan
  12.   FROM BD 
  13.   GROUP BY BD.Cod) AS J
  14. ON b.Cod = j.Cod  
Feb 27 '17 #2
Lirsy
6
Thank you VERY much!! Let me go for in now!! :-)

BTW, quite better ussing Nz!!
Feb 28 '17 #3

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

Similar topics

2
by: Mattyboy | last post by:
Guys I have built a database with saved queries that runs fine in Access but when I call it from the web using ASP, an exception occurs. I have tried multiple ways of testing the databases with...
2
by: Beda Christoph Hammerschmidt | last post by:
MySQL, Access, ODBC, Replication Hello, i have a central mysql database that is accesed by multiple clients running MS Access with ODBC. This works fine if Access has a permanent connection...
3
by: eagleofjade | last post by:
I am trying to help a friend who is learning VB.net in school. I have done VB programming for a number of years using VB 6. He needs to open a query in an Access database that has parameters so he...
9
by: noor.rahman | last post by:
I was wondering how it may be possible to query 2 MySQL databases using one query statement from PHP. For instance: SELECT database1.tableA.field1 UNION database2.tableB.field2. My concern...
3
by: Kevin Killion | last post by:
I've recently features to a system by making use of some simple MySQL access routines. It works fine at most test locations, correctkly accessing a MySQL database on an internet server. ...
16
by: laverdir | last post by:
<? $query = "SELECT " . $this->tabela3 . ".id, " . $this->tabela3 . ".naziv, " . $this->tabela3 . ".spisatelj, " . $this->tabela3 . ".najava, " . " DATE_FORMAT(" . $this->tabela3 ....
0
by: Hetal | last post by:
Hi.. I have a VB.NET (Windows forms) application and i would like to determine the type of database (SQL/MySQL/Access) i am connected to. In native VB6, say i have a connection object named...
5
by: abhilashcashok | last post by:
hi guys, my prblem is that I cannot update sql query against MS ACCESS using C#. Everytime wen i do so, i got an exception (at runtime) as 'UPDATE syntax not correct'. I don find any error in my...
1
by: almaroc | last post by:
my question is basically how to pass a parameter to a query in mysql. lets say i have a table with empno and empname and i want to select the empno based on the empname entered by the user. something...
0
by: cdsrenata | last post by:
Hello, I have a query in MySQL and I want to use it in Postgresql 9.3 but some functions don't exist in Postgresql! The code is this: CAST(CONCAT(TIMESTAMPDIFF(HOUR, ss.datahoralimite,...
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...
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
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...
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...
0
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,...

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.