Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ISNULL


ISNULL

Author
Message
Marius Els
Marius Els
SSC Veteran
SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)

Group: General Forum Members
Points: 218 Visits: 180
Comments posted to this topic are about the item ISNULL
BudaCli
BudaCli
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1166 Visits: 598
"The length of the value returned is always equal to or less than the field length of the checked expression"....

What you don't know won't hurt you but what you know will make you plan to know better
Carlo Romagnano
Carlo Romagnano
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3627 Visits: 3236
From BOL:
Return Types
Returns the same type as check_expression.

In this case, a cast from varchar(12) to varchar(10)
RedLlewy
RedLlewy
SSC-Addicted
SSC-Addicted (436 reputation)SSC-Addicted (436 reputation)SSC-Addicted (436 reputation)SSC-Addicted (436 reputation)SSC-Addicted (436 reputation)SSC-Addicted (436 reputation)SSC-Addicted (436 reputation)SSC-Addicted (436 reputation)

Group: General Forum Members
Points: 436 Visits: 1157
I find these questions great training - thanks!


RedLlewy
"The Plural of Anecdote is not Data"


Noel McKinney
Noel McKinney
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2017 Visits: 796
This is the main reason I make it a habit to use COALESCE rather than ISNULL unless there's a reason I need the behavior of ISNULL.
Carlo Romagnano
Carlo Romagnano
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3627 Visits: 3236
Noel McKinney (11/3/2009)
This is the main reason I make it a habit to use COALESCE rather than ISNULL unless there's a reason I need the behavior of ISNULL.

I prefer ISNULL because of performance.
Noel McKinney
Noel McKinney
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2017 Visits: 796
Carlo Romagnano (11/3/2009)
Noel McKinney (11/3/2009)
This is the main reason I make it a habit to use COALESCE rather than ISNULL unless there's a reason I need the behavior of ISNULL.

I prefer ISNULL because of performance.

Interesting, I can't recall coming across references to performance comparisons between COALESCE and ISNULL, but yes, there does seem to be a slight advantage in CPU time with ISNULL that could be noticed over a very large number of rows. However, in my environment, preventing unintended truncation of string values is more important than slight performance gains.
Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8337 Visits: 11580
Carlo Romagnano (11/3/2009)
Noel McKinney (11/3/2009)
This is the main reason I make it a habit to use COALESCE rather than ISNULL unless there's a reason I need the behavior of ISNULL.

I prefer ISNULL because of performance.


So, do you have any repro code that actually demonstrates a performance difference between COALESCE and ISNULL? If so, please post!

The only situation I know of is when an expression in COALESCE is a subquery - in those cases, ISNULL can be found to perform better. But how often does one actuallly need an entire subquery in COALESCE or ISNULL?

Like Noel, I use COALESCE rather than ISNULL. Because of the weird datatyping rules of ISNULL, but also because it supports more than two arguments, and because it's ANSI standard. The only reasons I'd ever prefer ISNULL are
1) If I have to use it in a view or computed column where the column has to be not nullable - any COALESCE expression is always nullable; ISNULL is only nullable is the second argument is nullable.
2) If any of the arguments has to be a subquery, because of the potential performance problems COALESCE has with those - and since this is acutally caused by an optimizer weakness, I'd make a note to check if the optimizer has finally improved in this respect after every version or servicepack upgrade.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Marius Els
Marius Els
SSC Veteran
SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)

Group: General Forum Members
Points: 218 Visits: 180
I've almost 'grown up' (professionally) with microsoft's sql standard, thus I'm not too familiar with ANSI standard.

I've played with COALESCE before, but I find ISNULL is sufficient for my requirements; I haven't had to deal with multiple arguments possibly being null and I don't work with large number of rows...

But it is good to know how to 'skin the cat' a different way

Thanks for the input guys
mtassin
mtassin
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4109 Visits: 72512
I too go with using ISNULL because I discovered it before COALESCE.

For multiple NULL values until I discovered COALESCE, I'd just chain ISNULL's

ISNULL(<test value>,ISNULL(<test value 2>,<final value))

etc.



--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search