Solved

SQL

Posted on 2002-06-27
7
151 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
Industry Leaders: 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 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…

752 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