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

Testing for non existing table entries

jimleon
74
The following query is supposed to bring up the electrical requirements of our customers (if any) based on their usaage last year.
It works great if that company was with us last year and has a company code in the last years electric table.

However if the customer is a new one then they wont have an entry in the table; I therefore us an iif statement to check on all fields that use the electrics last year table thus:

expr5: IIf(IsNull([last year stand no]),"x",[electrics last year].[spotlights])

which will output last years spotlight usage if that company was with us and an 'x' if it wasn't, allowing the query to finish sucessfully.

But this is not the case and I suspect my method of detecting if the company code is present in the table is faulty.

Any ideas guys??



SELECT [stands booked].[Company Code], [stands booked].[stand no], IIf(IsNull([last year stand no]),Right$([Forms]![Main Details]![Child17].[Form]![stand no],1),Right$([last year stand no],1)) AS Expr2, [show list].showcode, [show list].show, [Customer Details].CO_NAME, IIf(IsNull([last year stand no]),"x",[electrics last year].[power sockets 1]) AS expr3, IIf(IsNull([last year stand no]),"x",[electrics last year].[sunflood light]) AS expr4, IIf(IsNull([last year stand no]),"x",[electrics last year].[spotlights]) AS expr5, IIf(IsNull([last year stand no]),"x",[electrics last year].[20 amp single phase]) AS expr6, IIf(IsNull([last year stand no]),"x",[electrics last year].[30 amp three phase]) AS expr8, IIf(IsNull([last year stand no]),"x",[electrics last year].[60 amp supply]) AS expr9, IIf(IsNull([last year stand no]),"x",[electrics last year].[Special Reqs]) AS expr10, IIf(IsNull([last year stand no]),"x",[electrics last year].[srcost]) AS expr11, IIf(IsNull([last year stand no]),"x",[electrics last year].[water]) AS expr12, preferences.[daily supply cost], preferences.[sunflood light], preferences.spotlights, preferences.[20 amp single phase], preferences.[30 amp single phase], preferences.[30 amp three phase], preferences.[60 amo supply], preferences.[water cost], preferences.Year, [Year]-1 AS expr1, [stands booked].[None required]
FROM preferences, [show list], ([electrics last year] INNER JOIN [Customer Details] ON [electrics last year].SHORT_NAME = [Customer Details].SHORT_NAME) INNER JOIN [stands booked] ON [Customer Details].SHORT_NAME = [stands booked].[Company Code]
WHERE ((([stands booked].[Company Code])=[Forms]![Main Details]![Company Code]) AND (([stands booked].[stand no])=[Forms]![Main Details]![Child17].[Form]![stand no]) AND ((IIf(IsNull([last year stand no]),Right$([Forms]![Main Details]![Child17].[Form]![stand no],1),Right$([last year stand no],1)))=Right$([Forms]![Main Details]![Child17].[Form]![stand no],1)) AND (([show list].showcode)=Right$([Forms]![Main Details]![Child17].[Form]![stand no],1)) AND (([Customer Details].SHORT_NAME)=[Forms]![Main Details]![Company Code]) AND ((IIf(IsNull([last year stand no]),"x",[electrics last year].[SHORT_NAME]))=[Forms]![Main Details]![Company Code]));
Oct 9 '07 #1
2 1153
ADezii
8,834 Expert 8TB
The following query is supposed to bring up the electrical requirements of our customers (if any) based on their usaage last year.
It works great if that company was with us last year and has a company code in the last years electric table.

However if the customer is a new one then they wont have an entry in the table; I therefore us an iif statement to check on all fields that use the electrics last year table thus:

expr5: IIf(IsNull([last year stand no]),"x",[electrics last year].[spotlights])

which will output last years spotlight usage if that company was with us and an 'x' if it wasn't, allowing the query to finish sucessfully.

But this is not the case and I suspect my method of detecting if the company code is present in the table is faulty.

Any ideas guys??



SELECT [stands booked].[Company Code], [stands booked].[stand no], IIf(IsNull([last year stand no]),Right$([Forms]![Main Details]![Child17].[Form]![stand no],1),Right$([last year stand no],1)) AS Expr2, [show list].showcode, [show list].show, [Customer Details].CO_NAME, IIf(IsNull([last year stand no]),"x",[electrics last year].[power sockets 1]) AS expr3, IIf(IsNull([last year stand no]),"x",[electrics last year].[sunflood light]) AS expr4, IIf(IsNull([last year stand no]),"x",[electrics last year].[spotlights]) AS expr5, IIf(IsNull([last year stand no]),"x",[electrics last year].[20 amp single phase]) AS expr6, IIf(IsNull([last year stand no]),"x",[electrics last year].[30 amp three phase]) AS expr8, IIf(IsNull([last year stand no]),"x",[electrics last year].[60 amp supply]) AS expr9, IIf(IsNull([last year stand no]),"x",[electrics last year].[Special Reqs]) AS expr10, IIf(IsNull([last year stand no]),"x",[electrics last year].[srcost]) AS expr11, IIf(IsNull([last year stand no]),"x",[electrics last year].[water]) AS expr12, preferences.[daily supply cost], preferences.[sunflood light], preferences.spotlights, preferences.[20 amp single phase], preferences.[30 amp single phase], preferences.[30 amp three phase], preferences.[60 amo supply], preferences.[water cost], preferences.Year, [Year]-1 AS expr1, [stands booked].[None required]
FROM preferences, [show list], ([electrics last year] INNER JOIN [Customer Details] ON [electrics last year].SHORT_NAME = [Customer Details].SHORT_NAME) INNER JOIN [stands booked] ON [Customer Details].SHORT_NAME = [stands booked].[Company Code]
WHERE ((([stands booked].[Company Code])=[Forms]![Main Details]![Company Code]) AND (([stands booked].[stand no])=[Forms]![Main Details]![Child17].[Form]![stand no]) AND ((IIf(IsNull([last year stand no]),Right$([Forms]![Main Details]![Child17].[Form]![stand no],1),Right$([last year stand no],1)))=Right$([Forms]![Main Details]![Child17].[Form]![stand no],1)) AND (([show list].showcode)=Right$([Forms]![Main Details]![Child17].[Form]![stand no],1)) AND (([Customer Details].SHORT_NAME)=[Forms]![Main Details]![Company Code]) AND ((IIf(IsNull([last year stand no]),"x",[electrics last year].[SHORT_NAME]))=[Forms]![Main Details]![Company Code]));
It seems as though you would have to do some kind of Lookup on the [electrics last year] Table, something similar to:
Expand|Select|Wrap|Line Numbers
  1. expr5: IIf(IsNull([last year stand no]), "x", DLookup("[spotlights]", "[electrics last year]", _
  2.             & "[electrics last year].[last year stand no]=" & Me![last year stand no]))
Oct 9 '07 #2
Jim Doherty
897 Expert 512MB
The following query is supposed to bring up the electrical requirements of our customers (if any) based on their usaage last year.
It works great if that company was with us last year and has a company code in the last years electric table.

However if the customer is a new one then they wont have an entry in the table; I therefore us an iif statement to check on all fields that use the electrics last year table thus:

expr5: IIf(IsNull([last year stand no]),"x",[electrics last year].[spotlights])

which will output last years spotlight usage if that company was with us and an 'x' if it wasn't, allowing the query to finish sucessfully.

But this is not the case and I suspect my method of detecting if the company code is present in the table is faulty.

Any ideas guys??



SELECT [stands booked].[Company Code], [stands booked].[stand no], IIf(IsNull([last year stand no]),Right$([Forms]![Main Details]![Child17].[Form]![stand no],1),Right$([last year stand no],1)) AS Expr2, [show list].showcode, [show list].show, [Customer Details].CO_NAME, IIf(IsNull([last year stand no]),"x",[electrics last year].[power sockets 1]) AS expr3, IIf(IsNull([last year stand no]),"x",[electrics last year].[sunflood light]) AS expr4, IIf(IsNull([last year stand no]),"x",[electrics last year].[spotlights]) AS expr5, IIf(IsNull([last year stand no]),"x",[electrics last year].[20 amp single phase]) AS expr6, IIf(IsNull([last year stand no]),"x",[electrics last year].[30 amp three phase]) AS expr8, IIf(IsNull([last year stand no]),"x",[electrics last year].[60 amp supply]) AS expr9, IIf(IsNull([last year stand no]),"x",[electrics last year].[Special Reqs]) AS expr10, IIf(IsNull([last year stand no]),"x",[electrics last year].[srcost]) AS expr11, IIf(IsNull([last year stand no]),"x",[electrics last year].[water]) AS expr12, preferences.[daily supply cost], preferences.[sunflood light], preferences.spotlights, preferences.[20 amp single phase], preferences.[30 amp single phase], preferences.[30 amp three phase], preferences.[60 amo supply], preferences.[water cost], preferences.Year, [Year]-1 AS expr1, [stands booked].[None required]
FROM preferences, [show list], ([electrics last year] INNER JOIN [Customer Details] ON [electrics last year].SHORT_NAME = [Customer Details].SHORT_NAME) INNER JOIN [stands booked] ON [Customer Details].SHORT_NAME = [stands booked].[Company Code]
WHERE ((([stands booked].[Company Code])=[Forms]![Main Details]![Company Code]) AND (([stands booked].[stand no])=[Forms]![Main Details]![Child17].[Form]![stand no]) AND ((IIf(IsNull([last year stand no]),Right$([Forms]![Main Details]![Child17].[Form]![stand no],1),Right$([last year stand no],1)))=Right$([Forms]![Main Details]![Child17].[Form]![stand no],1)) AND (([show list].showcode)=Right$([Forms]![Main Details]![Child17].[Form]![stand no],1)) AND (([Customer Details].SHORT_NAME)=[Forms]![Main Details]![Company Code]) AND ((IIf(IsNull([last year stand no]),"x",[electrics last year].[SHORT_NAME]))=[Forms]![Main Details]![Company Code]));

To reconstitute tables based on that SQL is going to be a pain my end to debug in the absence of your db table fieldnames, datatypes and so on... so heres a clue for you to look at.

Check out the subtle difference in SQL language between INNER JOINS and LEFT JOINS in other words in an attempt to explain the concept in plain english for your circumstances

1) an LEFT JOIN means "Show me all Customers according to a certain criteria irrespective of whether or not they have a record in the electrics last years table"

2) an INNER JOIN is "Show me all Customers according to a certain criteria only if they have a record in the electrics last years table"

Inner joins, left joins, right joins etc can be created by you by playing with the line that joins the tables together in the query window. double click it to see what it does. It may well prompt you to have a 'rethink' on your query design.

As I see it initially you should have a serious look at LEFT joining because when structured correctly, it will display existing customers to you, even though they do not appear in last years records.

(You will know when you have a left join when you see the line change to an arrow in the query window switch to SQL view to see the resultant SQL)

I hope this makes sense to you.

Regards

Jim
Oct 9 '07 #3

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

Similar topics

5
by: Arvin Portlock | last post by:
I can't come up with a query that works. Can anyone help? Conceptually the relationships are easy to describe. I have a table for books (Entries), a table for authors (Authors), and a linking...
3
by: Ole Hanson | last post by:
Hi I am trying to engineer a way of testing that my logging framework is capable of writing to my eventlog. I want to include this test in my already existing NUnit tests - but I'm a little low...
1
by: Nils Rennebarth | last post by:
I have a table that is essentially a log where new entries are streaming in continually and from time to time I throw old entries away to keep the table from growing. I understand that in...
13
by: nyt | last post by:
I have a problem of number and text field. I got the database file(mdb) that contains many combo boxes used and its list values are created by "value list" For eg field Field name= 'furniture'...
2
by: chuy08 | last post by:
Basically I am using PHP 5.1.2 with Apache 2.0.5 on a FreeBSD 5.4 box with Mysql 4.1.1 running. I am attempting to write information to a Mysql table called Jabber. I can connect successfully,...
1
by: exapplerep | last post by:
I have a table with a particular field storing the names of authors. When I enter a new record I'd like to have a list of the existing entries come up from which one may choose. It is also...
2
by: DavidPr | last post by:
I'm creating (trying to create) a picture gallery for my website. The script is not working. I've been working on it now for about 80 hours with no success. My php skills aren't very good. This...
14
by: deejow | last post by:
U guys/gals are awesome! I have a "Claimant Master" table with a primary key called "Claimant ID" set to number data type. It has existing records linked to an enormous "Jobs" table. There are...
10
by: hedges98 | last post by:
I'm not sure if the title of the thread is relevant but I think it explains my problem... This is going to be loooooong... Basically, I am working on altering/improving an existing database but...
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?
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
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
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...
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.