Re: SQL query re unions and nulls
Posted in 1997
At 07:07 PM 9/09/97 GMT, you wrote:
}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.
}
This will help you:
Create a stored Procedure like this:
create procedure retnull() returning char; define ret char;
let ret = "";
return null;
end procedure;
then you can use it like follow:
select a,b,c,d,retnull()
from x
where ....
union
select a,b,c,retnull(),e
from x
where ...
@@@@ @@@@@@@ Mauro G. Pisano
@@@ @@@ @@@ @ Analista Programador.
@@@ @ @ @@@@@@@ Direcc. Gral. de Cultura y Educaci'n.
@@@ @ @@@ - Liquidacion de Sueldos
Transferidos/EGB -
@@@ @@@ Email: mpisano@ed.gba.gov.ar