|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, October 31, 2012 3:59 AM
Points: 215,
Visits: 166
|
|
| Comments posted to this topic are about the item ISNULL
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, March 27, 2013 9:02 AM
Points: 1,046,
Visits: 573
|
|
"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
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: 2 days ago @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
From BOL: Return Types Returns the same type as check_expression.
In this case, a cast from varchar(12) to varchar(10)
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: 2 days ago @ 3:06 AM
Points: 367,
Visits: 845
|
|
I find these questions great training - thanks!
RedLlewy "The Plural of Anecdote is not Data"
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, April 05, 2012 2:35 PM
Points: 2,007,
Visits: 767
|
|
| 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.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: 2 days ago @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
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.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, April 05, 2012 2:35 PM
Points: 2,007,
Visits: 767
|
|
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.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 11:51 AM
Points: 5,232,
Visits: 7,023
|
|
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
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, October 31, 2012 3:59 AM
Points: 215,
Visits: 166
|
|
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
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 9:35 PM
Points: 3,226,
Visits: 64,096
|
|
|
|
|