Solved

SQL

Posted on 2002-06-27
7
146 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
Comment Utility
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
Comment Utility
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
Comment Utility
Change the field definition in the Invoiced table into long integer.
BTW what database are you using?

Nic;o)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:HotRod40
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now