473,395 Members | 1,668 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.

Return 0 IFNULL Some Help Please

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,

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. Job_No,
  3. IFNULL((SELECT sum(Paying_Rate*Working_Hrs) FROM Labour WHERE Job_No = Job.Job_No),0) AS Labsubtotal,
  4. IFNULL((SELECT sum(Quantity*Unit_Price+(Quantity*Unit_Price*+Additional_Cost/100)) FROM Material WHERE Job_No = Job.Job_No),0) AS Matsubtotal,
  5. Labsubtotal*0.175 AS Labvat,
  6. Matsubtotal*0.175)AS Matvat,
  7. Matsubtotal + Labsubtotal AS subtotal,
  8. Labsubtotal*0.175 + Matsubtotal*0.175  AS vat,
  9. Labsubtotal*1.175 + Matsubtotal*1.175 AS TOTAL,
  10. Job.Order_Date,
  11. Job.File_No,
  12. Job.Contract,
  13. Job.Order_Site_Address,
  14. Job.Job_Description,
  15. Job.Invoice_Tax_Date, 
  16. Job.CustomerRef,
  17. Job.Customer_Name,
  18. Customer.Billing_Address
  19. FROM Job
  20. LEFT JOIN Customer
  21. 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.
Apr 4 '08 #1
3 4815
Stewart Ross
2,545 Expert Mod 2GB
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
Apr 4 '08 #2
Thanks Stewart.

I changed my statement to

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. Job_No,
  3. Nz([SELECT sum(Paying_Rate*Working_Hrs)],0) AS Labsubtotal,
  4. Nz([SELECT sum(Quantity*Unit_Price+(Quantity*Unit_Price*+Addi  tional_Cost/100)) ],0) AS Matsubtotal,
  5. Labsubtotal*0.175 AS Labvat,
  6. Matsubtotal*0.175 AS Matvat,
  7. Matsubtotal + Labsubtotal AS subtotal,
  8. Labsubtotal*0.175 + Matsubtotal*0.175  AS vat,
  9. Labsubtotal*1.175 + Matsubtotal*1.175 AS TOTAL,
  10. Job.Order_Date,
  11. Job.File_No,
  12. Job.Contract,
  13. Job.Order_Site_Address,
  14. Job.Job_Description,
  15. Job.Invoice_Tax_Date, 
  16. Job.CustomerRef,
  17. Job.Customer_Name,
  18. Customer.Billing_Address
  19. FROM Job
  20. inner JOIN Customer
  21. ON Job.Customer_Name=Customer.Customer_Name
  22. inner JOIN Labour
  23. ON Job.Job_No=Labour.Job_No
  24. inner JOIN Material
  25. 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

Expand|Select|Wrap|Line Numbers
  1. Job.Customer_Name=Customer.Customer_Name
  2. inner JOIN Labour
  3. ON Job.Job_No=Labour.Job_No
  4. inner JOIN Material
  5. ON Job.Job_No=Material.Job_No
Thanks
Paul.
Apr 5 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
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.

Expand|Select|Wrap|Line Numbers
  1. SELECT Job.Job_no, 
  2. Nz(Sum([Paying_Rate]*[Working_Hrs]),0) AS Labsubtotal, 
  3. Nz(Sum([Quantity]*[Unit_Price]+([Quantity]*[Unit_Price]*+[Additional_Cost]/100)),0) AS Matsubtotal, 
  4. 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, 
  5. Job.Order_date, 
  6. Job.File_No, 
  7. Job.Contract, 
  8. Job.Order_Site_Address, 
  9. Job.Job_Description, 
  10. Job.Invoice_Tax_date, 
  11. Job.CustomerRef, 
  12. Job.Customer_Name, 
  13. Customer.Billing_Address
  14. FROM 
  15. ((Job INNER JOIN Customer ON Job.Customer_Name = Customer.Customer_Name) 
  16. INNER JOIN Labour ON Job.Job_no = Labour.job_No) 
  17. INNER JOIN Materials ON Job.Job_no = Materials.Job_no
  18. 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
Apr 5 '08 #4

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

Similar topics

2
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...
2
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...
8
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...
18
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...
1
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...
2
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...
7
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: ...
5
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(); }
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
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: 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
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
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...
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.