View Single Post

   
  #2 (permalink)  
Old 02-29-2008, 03:21 AM
Hugo Kornelis
 
Posts: n/a
Default Re: Prepared Statement where value IS null or value = :x

On 4 Apr 2004 23:46:17 -0700, Kevin Frey wrote:

>Hello,
>
>I have a table which contains some nullable columns. I want to write a
>single query, which can be prepared (ie. prepared statement), that can
>handle null or non-null values for the where clause. Is this possible
>in a standard-conforming manner?
>
>The simple for of the query is this:
>
>SELECT * FROM <table> WHERE <column> = <value>
>
>But when the value to be matched on is NULL, the syntax of the query
>must change to be:
>
>SELECT * FROM <table> WHERE <column> IS <value>
>
>In the second case <value> is NULL.
>
>I know one option might be to change the ANSI NULL handling option,
>but I am loathe to do this (I have five RDBMS's to support, not just
>MSSSQL).
>
>I thought I might have been able to cheat using an IN clause to make
>the SQL consistent, but no luck.
>
>Thanks
>
>Kevin


The syntax you show in the subject of this message should work:

SELECT <columns>
FROM <table>
WHERE <column> = <value>
OR <column> IS NULL

If that doesn't help you, please post actual DDL and sample data (in
the form of insert statements) to help us reproduce and then solve
your problem.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Reply With Quote