Board index » delphi » How present empty fields with a SQL statement?

How present empty fields with a SQL statement?

Hi sirs

I have a table with a code in each record, this code is the reference to my
customers table.
I want to retrieve the original table, with the code and the name of the
customer (the name
is only in the customers table) , (the name in the result is just like a
lookup field).

To do this i do:

Select A.Code, C.Name
from fac.db A, cust.db C
where (C.Code=A.Code)
Order by C.Name

The problem is that the elements in table A where the field code is empty
are not in the result
list and i want them, if i use Where (C.Code=A.Code) or (A.Code='') the
applications
hangs up. Why?

Another question  is:

How can i do a lookup field in a Query and make an Order by this lookup
field?

 

Re:How present empty fields with a SQL statement?


Sir,

What you want is an outer join:

Select A.Code, C.Name
from fac.db A LEFT OUTER JOIN cust.db C ON C.Code = A.Code
Order by C.Name

This will return every record in the fac.db table whether there is a match
in the cust.db table or not.

I'm not sure that I understand your second question.  Isn't that what you're
doing with an ORDER BY statement?

HTH - Mike

Quote
LADRILLO <l...@elladrillorojo.com> wrote in message

news:88e2kq$lfb1@bornews.borland.com...
Quote
> Hi sirs

> I have a table with a code in each record, this code is the reference to
my
> customers table.
> I want to retrieve the original table, with the code and the name of the
> customer (the name
> is only in the customers table) , (the name in the result is just like a
> lookup field).

> To do this i do:

> Select A.Code, C.Name
> from fac.db A, cust.db C
> where (C.Code=A.Code)
> Order by C.Name

> The problem is that the elements in table A where the field code is empty
> are not in the result
> list and i want them, if i use Where (C.Code=A.Code) or (A.Code='') the
> applications
> hangs up. Why?

> Another question  is:

> How can i do a lookup field in a Query and make an Order by this lookup
> field?

Other Threads