<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Never Say Never &#187; Functions</title>
	<atom:link href="http://phelabaum.com/archive/tag/functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://phelabaum.com</link>
	<description>MS SQL Server Development</description>
	<lastBuildDate>Thu, 29 Sep 2011 02:20:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ISNULL() VS. COALESCE()</title>
		<link>http://phelabaum.com/archive/2010/02/isnull-vs-coalesce-2/</link>
		<comments>http://phelabaum.com/archive/2010/02/isnull-vs-coalesce-2/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 13:47:50 +0000</pubDate>
		<dc:creator>Seth Phelabaum</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://phelabaum.com/archive/2010/02/isnull-vs-coalesce-2/</guid>
		<description><![CDATA[There are a lot of arguments about which of these to use.&#160; In my opinion, they both have their place.&#160; Here are a few facts about the two functions. ISNULL can accept only two arguments where as COALESCE can accept any number of input parameters ISNULL is not ANSI standard and is proprietary to TSQL. [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of arguments about which of these to use.&#160; In my opinion, they both have their place.&#160; Here are a few facts about the two functions. </p>
<ul>
<li>ISNULL can accept only two arguments where as COALESCE can accept any number of input parameters </li>
<li>ISNULL is not ANSI standard and is proprietary to TSQL. </li>
<li>With ISNULL, the datatype of the second argument is converted to equal the data type of the first argument where as COALESCE converts according to data type precedence.&#160; </li>
<li>ISNULL is generally accepted to be faster than COALESCE. </li>
<li>COALESCE is a much cooler word and will usually earn you either an impressed glance or a blank confused stare when slipped into casual conversation.&#160; </li>
</ul>
<p>Here are a few examples that demonstrate some of the functional differences between the two conversion methods. </p>
<pre class="csharpcode"><span class="kwrd">declare</span> @a <span class="kwrd">varchar</span>(5)
<span class="kwrd">select</span> ISNULL(@a, <span class="str">'ISNULL Test 1'</span>)        <span class="rem">-- Result: ISNUL</span>
<span class="kwrd">SELECT</span> <span class="kwrd">COALESCE</span>(@a, <span class="str">'COALESCE Test 1'</span>)    <span class="rem">-- Result: COALESCE Test 1</span>

<span class="kwrd">declare</span> @b tinyint
<span class="kwrd">SELECT</span> ISNULL(@b, 99999)                <span class="rem">-- Result: **Error**</span>
<span class="kwrd">SELECT</span> <span class="kwrd">COALESCE</span>(@b, 99999)                <span class="rem">-- Result: 9999</span>

<span class="kwrd">declare</span> @c <span class="kwrd">char</span>(5)
<span class="kwrd">SELECT</span> ISNULL(@c, <span class="str">'a'</span>) + <span class="str">'B'</span>            <span class="rem">-- Result: a    B</span>
<span class="kwrd">SELECT</span> <span class="kwrd">COALESCE</span>(@c, <span class="str">'a'</span>) + <span class="str">'B'</span>            -- <span class="kwrd">Result</span>: aB</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://phelabaum.com/archive/2010/02/isnull-vs-coalesce-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

