SQL query re unions and nulls
Posted in 1997
Topics: SQL Development & Query Writing, Connectivity: ODBC / JDBC / .NET
I'd really appreciate some help with this particular SQL problem I've
been landed with. I need to write two selects joined by a union to
deliver separate subsets of columns.
Consider a table x with columns a,b,c,d,e all of which are type
integer. Depending on various entries in the where clauses, I need
columns a,b,c,d from the first select and a,b,c,e from the second but
I need all five columns in total.
What I need is something like the following:
select a,
b,
c,
d,
null
from x
where ....
union
select a,
b,
c,
null,
e
from x
where ...
The problem is how to specify a literal null - if the fields where
char(n) then I could live with blanks or even two quotes together but
that won't work for numeric type fields.
One last thing, I need a solution that will work on Informix and
Sybase through ODBC.
Thanks in advance if anyone can help