Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need Professional Opinion

Author  Topic 

takkone
Starting Member

8 Posts

Posted - 2011-07-27 : 15:41:49
We have an vendor's application here which uses SQL Server backend. I captured some commands it sends to SQL Server behind the scenes based on users' actions and I thought this one was not quite correct. This is the WHERE clause the app sends to the server when the user asks for a list of records where the c2.UDLACCT01 field "is empty":

WHERE (UPPER(c2.UDLACCT01) = '' OR UPPER(c2.UDLACCT01) <= ' ' OR UPPER(c2.UDLACCT01) IS NULL)

Seems to me the more correct way would be something like this:
WHERE ISNULL(RTRIM(LTRIM(c2.UDLACCT01)),'') = ''

Or maybe either would be acceptable, what do you think?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-27 : 15:49:59
My opinion: No need to change.
In difference to your idea the original statement checks also if there are chars < space (which maybe ascii(13) for example).


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-07-27 : 18:41:18
How about
WHERE c2.UDLACCT01 = '' OR c2.UDLACCT01 IS NULL? It can use indexes, neither the original nor your version can because of the functions.

(SQL ignores trailing spaces when comparing, so ' ' = '')

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -