Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL

Posted on 2002-06-27
7
Medium Priority
?
153 Views
Last Modified: 2010-04-04
Hi,

Could anyone please help!
I want to connect 4 tables together to allow for access to information in other records.
I need to be able to look for the criteria of:

'If the 'PreInvoiceDate' field is less than or equal to a system date and for the 'InvoicedId' field to be blank.

The above works OK and retrieves a records information until I add the table named 'INVOICED' and the below information into the SQL query (the or statement):

'If the field InvoiceID is not blank (ie a record exists) then check for the 'FirstInvoice' field to be blank

If I add the above code then no information appears at all.
Whats wrong?
Here is the full code:

SELECT *
FROM CUSTOMER cu,
            CONTRACT c,
            FEEINFO f,
            INVOICED i   /*Problem Here*/
WHERE c.'contract number' = cu.'contract number' and
c.'contract number' = f.'contractid' and
c.'contract number' = i.'contractid' and  /*Problem Here*/
f.'preinvoicedate' <= '08/28/2002' and
(f.'invoicedid' is null or (f.'invoicedid' is not null and i.'firstinvoice' is null))     /*Problem Here*/

Many Thanks in anticipation
Scott
0
Comment
Question by:HotRod40
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 54

Expert Comment

by:nico5038
ID: 7113130
I would try a subquery on the INVOICED table like:

SELECT *
FROM CUSTOMER cu,
           CONTRACT c,
           FEEINFO f,
           INVOICED i   /*Problem Here*/
WHERE c.'contract number' = cu.'contract number' and
c.'contract number' = f.'contractid' and
c.'contract number' = i.'contractid' and  /*Problem Here*/
f.'preinvoicedate' <= '08/28/2002' and
(f.'invoicedid' NOT IN (SELECT invoicedid FROM INVOICED WHERE firstinvoice not is null) )

This adds a NOT IN the set of "wrong" ID's with a first invoice filled.
Getting the idea ?

Nic;o)
0
 

Author Comment

by:HotRod40
ID: 7113140
Thanks for that it does make things more clear except for one problem.
I receive a Type Mismatch error and I think it is because of the following:


TABLE          FIELDNAME       TYPE
             
FeeInfo       InvoicedID       Auto (+)
Invoiced      InvoicedID       String (A)

Any more suggestions?
Thanks Again..  
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7113151
Change the field definition in the Invoiced table into long integer.
BTW what database are you using?

Nic;o)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:HotRod40
ID: 7113157
I need an auto gen number to be created in the Invoiced table.
I presume that this will no longer happen??
And will the system recognize a long int and a string to be the same??

My database is Paradox. The dbase that comes with Delphi5

Thanks
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7113181
I'm a bit puzzled:
>I need an auto gen number to be created in the Invoiced table.
According to your comment above it's a string. Normally an autounumber is numeric (In MS Access it's format is a long integer)
But if Paradox accepts a string, then you need to make the FeeInfo "foreign key" also string to prevent the type-mismatch.

Nic;o)
0
 

Author Comment

by:HotRod40
ID: 7113396
Thanks I have changed the Data types.
The problem seemd to be when I include the Invoiced table to my query. This table is empty by the way.
As soon as I include this table, my records previously found are no longer retrieved?
Weird???
0
 
LVL 54

Accepted Solution

by:
nico5038 earned 450 total points
ID: 7113664
That will be caused by the fact that SQL will only show rows when there are rows to display. An empty table "tells" the database engine not hits will be scored.
Oops, now I see my "error" try:
SELECT *
FROM CUSTOMER cu,
          CONTRACT c,
          FEEINFO f
WHERE c.'contract number' = cu.'contract number' and
c.'contract number' = f.'contractid' and
c.'contract number' = i.'contractid' and  /*Problem Here*/
f.'preinvoicedate' <= '08/28/2002' and
(f.'invoicedid' NOT IN (SELECT invoicedid FROM INVOICED WHERE firstinvoice not is null) )

Thus the INVOICE table is only referenced in the subquery !

Nic;o)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question