Why is there STILL no sql shortcut to include/not include null values in a where condition? [closed]

StackOverflow https://stackoverflow.com/questions/10458621

  •  05-06-2021
  •  | 
  •  

Question

 select 1 where somevalue = '' or somevalue is null from sometable

I completely understand the reasoning behind why I have to have two separate conditions. What baffles my mind is why after so many years there still isn't a standard shortcut notation for this.

I can see why various dbms implementations don't offer a shortcut since it isn't necessary and doing so would make your sql that much less portable, but considering the usefulness of such a shortcut across all dbms's I can't comprehend why the powers that be haven't added a shortcut to do this into the sql specifications.

My question: Is there actually a legitimate reason and if so what is it?

Was it helpful?

Solution

You could just

select * from table where isnull(columnname,'')=''

or if you are worried about ' ' values then you would use ltrim and/or rtrim.

OTHER TIPS

I'm used to working in Oracle, where the empty string is NULL, but wouldn't this work?

SELECT 1 FROM sometable WHERE COALESCE( somevalue, '' ) = ''

I don't see the issue. The only strangeness is caused by Oracle's not following the standard in making NULL the same as ''.

It is pretty easy to to this: coalesce(columnname,'')=''

On MS SQL Server you can also use this: isnull(columnname,'')=''

But be aware it is a MS only function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top