Hello all.
I am in the need of some help please.
I have an SQL statement that works on a MySQL Database, but I need to get it to work on an Access Database.
The statement is, - SELECT
-
Job_No,
-
IFNULL((SELECT sum(Paying_Rate*Working_Hrs) FROM Labour WHERE Job_No = Job.Job_No),0) AS Labsubtotal,
-
IFNULL((SELECT sum(Quantity*Unit_Price+(Quantity*Unit_Price*+Additional_Cost/100)) FROM Material WHERE Job_No = Job.Job_No),0) AS Matsubtotal,
-
Labsubtotal*0.175 AS Labvat,
-
Matsubtotal*0.175)AS Matvat,
-
Matsubtotal + Labsubtotal AS subtotal,
-
Labsubtotal*0.175 + Matsubtotal*0.175 AS vat,
-
Labsubtotal*1.175 + Matsubtotal*1.175 AS TOTAL,
-
Job.Order_Date,
-
Job.File_No,
-
Job.Contract,
-
Job.Order_Site_Address,
-
Job.Job_Description,
-
Job.Invoice_Tax_Date,
-
Job.CustomerRef,
-
Job.Customer_Name,
-
Customer.Billing_Address
-
FROM Job
-
LEFT JOIN Customer
-
ON(Job.Customer_Name=Customer.Customer_Name)
I am having trouble with the IFNULL part as it comes back with an Undefined Function.
I have searched through the forums, and found one with Nz, but I tried to substitute the code, but it wont and comes back with undefined functions.
If anybody can help, I would be greatful.
Thanks
Paul.
3 4815
Hi. Nz should be a straightforward substitute for your IFNULL. Its syntax is Nz([some expression], value to return), the same as the IFNULL.
I am not sure that the subqueries inside the IFNULLs will be accepted by Access, however (in that they are returning sets of values as fields within your outermost SELECT statement).
You would be able to do away with the subqueries if you joined the labour and materials tables to your query on the job_no field. It would not take you long to use the Access query editor to join your tables and select the relevant fields. Access generates the SQL for the query from the graphical query editor selections and joins on the fly.
If Nz is not recognised (there have been cases where it is treated as invalid for reasons that remain unclear) an alternative is to use an in-line if (IIF) statement with the IsNull function: IIF(IsNull([some value]), 0, [some value])
-Stewart
Thanks Stewart.
I changed my statement to - SELECT
-
Job_No,
-
Nz([SELECT sum(Paying_Rate*Working_Hrs)],0) AS Labsubtotal,
-
Nz([SELECT sum(Quantity*Unit_Price+(Quantity*Unit_Price*+Addi tional_Cost/100)) ],0) AS Matsubtotal,
-
Labsubtotal*0.175 AS Labvat,
-
Matsubtotal*0.175 AS Matvat,
-
Matsubtotal + Labsubtotal AS subtotal,
-
Labsubtotal*0.175 + Matsubtotal*0.175 AS vat,
-
Labsubtotal*1.175 + Matsubtotal*1.175 AS TOTAL,
-
Job.Order_Date,
-
Job.File_No,
-
Job.Contract,
-
Job.Order_Site_Address,
-
Job.Job_Description,
-
Job.Invoice_Tax_Date,
-
Job.CustomerRef,
-
Job.Customer_Name,
-
Customer.Billing_Address
-
FROM Job
-
inner JOIN Customer
-
ON Job.Customer_Name=Customer.Customer_Name
-
inner JOIN Labour
-
ON Job.Job_No=Labour.Job_No
-
inner JOIN Material
-
ON Job.Job_No=Material.Job_No
Now, I just need to find out more about inner joins, and left joins as I am getting a SYntax Error, Missing Operator in - Job.Customer_Name=Customer.Customer_Name
-
inner JOIN Labour
-
ON Job.Job_No=Labour.Job_No
-
inner JOIN Material
-
ON Job.Job_No=Material.Job_No
Thanks
Paul.
Hi Paul. You hadn't actually removed the subqueries (which, as I thought, Access does not like). Also, the syntax errors arose because there was no bracketing of the inner joins.
Here's a corrected version, tested on some dummy data. You will have to test it yourself to make sure all calculations work as expected. - SELECT Job.Job_no,
-
Nz(Sum([Paying_Rate]*[Working_Hrs]),0) AS Labsubtotal,
-
Nz(Sum([Quantity]*[Unit_Price]+([Quantity]*[Unit_Price]*+[Additional_Cost]/100)),0) AS Matsubtotal,
-
Labsubtotal*0.175 AS Labvat, Matsubtotal*0.175 AS Matvat, Matsubtotal+Labsubtotal AS subtotal, Labsubtotal*0.175+Matsubtotal*0.175 AS vat, Labsubtotal*1.175+Matsubtotal*1.175 AS TOTAL,
-
Job.Order_date,
-
Job.File_No,
-
Job.Contract,
-
Job.Order_Site_Address,
-
Job.Job_Description,
-
Job.Invoice_Tax_date,
-
Job.CustomerRef,
-
Job.Customer_Name,
-
Customer.Billing_Address
-
FROM
-
((Job INNER JOIN Customer ON Job.Customer_Name = Customer.Customer_Name)
-
INNER JOIN Labour ON Job.Job_no = Labour.job_No)
-
INNER JOIN Materials ON Job.Job_no = Materials.Job_no
-
GROUP BY Job.Job_no, Job.Order_date, Job.File_No, Job.Contract, Job.Order_Site_Address, Job.Job_Description, Job.Invoice_Tax_date, Job.CustomerRef, Job.Customer_Name, Customer.Billing_Address;
I note the use of two arithmetic operators *+ in sequence in line 3 of this code (as in all versions of your code) which I suggest you check and resolve, as it will simply be equivalent to the multiplication alone at present.
-Stewart
Sign in to post your reply or Sign up for a free account.
Similar topics
by: PengYu.UT |
last post by:
I have the following sample program, which can convert function object
with 1 argument into function object with 2 arguments. It can also do +
between function object of the same type.
The last...
|
by: Steve Crawford |
last post by:
Having a requirement to change null into a certain value in a query I
created a couple versions of an ifnull function as follows:
create or replace function "ifnull" (text, text) returns text as...
|
by: jbonifacejr |
last post by:
Hi. I'm sorry to bother all of you, but I have spent two days looking
at code samples all over the internet, and I can not get a single one
of them to work for me. I am simply trying to get a value...
|
by: Axel Dahmen |
last post by:
Hi,
trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project.
Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client...
|
by: darla0520 |
last post by:
Hi,
Please anyone help me, I have a datagrid on my child window wherein I have to return the value of the datagrid on the parent window when I click the link button.
Or do you have any sample code...
|
by: thuythu |
last post by:
Please help me....
I used and Javascript to view the data. But when i click button open a popup windows, then select data and click save button. The popup close and return the main page, but the...
|
by: enrico via DotNetMonster.com |
last post by:
i'm using mySQL as my backend to my program. i know this is not VB.NET
anymore but i don't know how to do it. i have a query that will calculate if
it satisfies the condition. it goes like this:
...
|
by: hirsh.dan |
last post by:
Hello to all, i have the following functions:
string File::readLine(){
char ch;
string str;
ch = read();
while(ch != LF && ch != CR && ch != -1){
str.append(1,ch);
ch = read();
}
|
by: TompIfe |
last post by:
Hi,
I have a web service that reads data from an Access database using
datareader and place the data in an array that
the web method returns.
Now, I want to make the web service also to return an...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |