| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: 3 value logic. Why is SQL so special?
Chris Lim wrote:
> SELECT FirstName,
> LastName,
> ISNULL(MiddleName, '') AS MiddleName,
Bad example of ISNULL since it's not required in this case!
A simpler example:
SELECT CustomerID,
FirstName
+ ISNULL(' ' + MiddleName, '')
+ ' ' + LastName AS FullName
FROM Customers
If you don't have a problem with outer joins then it's not too bad, but you still have to deal with NULLs:
SELECT C.CustomerID,
C.FirstName
+ ISNULL(' ' + CM.MiddleName, '')
+ ' ' + C.LastName AS FullName
FROM Customers C
ON CM.CustomerID = C.CustomerID
Otherwise it requires a UNION:
SELECT C.CustomerID,
C.FirstName
+ ' ' + C.LastName AS FullName
FROM Customers C
SELECT *
FROM CustomerMiddleName CM
WHERE CM.CustomerID = C.CustomerID
)
UNION SELECT C.CustomerID,
C.FirstName
+ ' ' + CM.MiddleName
+ ' ' + C.LastName AS FullName
FROM Customers C
ON CM.CustomerID = C.CustomerID
Chris Received on Tue Sep 19 2006 - 04:28:41 CDT
![]() |
![]() |