Solved

SQL

Posted on 2002-06-27
7
148 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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 150 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

Gigs: Get Your Project Delivered by an Expert

Select from 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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

786 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