Thread: coalesce?
View Single Post

   
  #3 (permalink)  
Old 02-27-2008, 11:31 AM
Lennart
 
Posts: n/a
Default Re: coalesce?


raysefo wrote:
> Hi,
>
> I m trying to use coalesce but i m getting this error below, btw i m
> using db2 8.2.
> what i m doing is;
> ...
> where eh.toblm = coalesce(NULL,eh.toblm)
>
> SQL0206N "NULL " is not valid in the context where it is used.
>
> Actually what i want to do is, get the result of this select statement
> either @id is NOT NULL or NULL! if @id is NULL then all results should
> be displayed!
> ...
> where eh.toblm = coalesce(@id,eh.toblm)


I'm not sure I fully understand your requirements, but in you example
you probably need to cast null to whatever type eh.toblm is. Example:

[lelle@53dbd181 lelle]$ db2 "select * from sysibm.sysdummy1 where
IBMREQD = coalesce(null, IBMREQD)"
SQL0206N "NULL" is not valid in the context where it is used.
SQLSTATE=42703

[lelle@53dbd181 lelle]$ db2 "select * from sysibm.sysdummy1 where
IBMREQD = coalesce(cast(null as char), IBMREQD)"

IBMREQD
-------
Y

1 record(s) selected.

HTH
/Lennart

Reply With Quote