June 30, 2008 at 8:17 am
Hi all,
I'm new here, but not new to SQL Server, I just like to ask everyone's opinion with negation, which is better and why?
having...
Where LEN(Message) > 0
OR
Where Message IS NOT NULL
IMHO, I prefer option 1.
June 30, 2008 at 8:49 am
This is not a great question.
The two options may not give you the same result.
It is typically better to not use a function within a join or where clause in a query because they have to be evaluated before doing the comparison - making indexes irrelevant.
July 7, 2008 at 12:56 pm
This is similar to the SARG discussion
July 7, 2008 at 1:06 pm
They do not produce the same results; see below:
create table #t ( Message varchar(20), seq int not null identity(1,1))
insert #t
select null union all
select '' union all
select 'xxx'
select * from #t where len(Message) > 0
select * from #t where Message is not null
Results:
Message seq
-------------------- -----------
xxx 3
(1 row(s) affected)
Message seq
-------------------- -----------
2
xxx 3
(2 row(s) affected)
July 11, 2008 at 9:39 pm
Better suggestion, make the app do length check and take the appopriate action.
July 11, 2008 at 11:09 pm
Ahi va:
Where LEN(isnull(Message, '')) > 0
Saludos,
José Miguel Gutiérrez Hilaccama
Database Developer - MCTS SQL Server 2005
No way Jose? ... bah
July 13, 2008 at 11:46 pm
WHERE (MESSAGE IS NOT NULL) AND (MESSAGE<>'')
This is better compare to Len function.
* For More info read Index Topic.
July 16, 2008 at 2:50 pm
Depending on what you are trying to achieve you can also use LIKE '_%'.
This will exclude NULLs an empty strings '' (but not the single space strings ' ').
Best Regards,
Chris Büttner
July 16, 2008 at 2:53 pm
Christian Buettner (7/16/2008)
Depending on what you are trying to achieve you can also use LIKE '_%'.This will exclude NULLs an empty strings '' (but not the single space strings ' ').
I like this answer the best, although as he says, "Depending", but in general using a function on a column in a where clause or join is a bad idea.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
July 24, 2008 at 11:45 am
I prefer the (Where LEN(isnull(Message, '')) > 0) method.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
July 25, 2008 at 8:33 am
Here is another option that could be used:
where isnull(Message,'') > ''
August 2, 2008 at 3:02 pm
Another option could be an implicit varbinary conversion such as
where message > 0x
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply