<?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>youdidwhatwithtsql.com &#187; collations</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/collations/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:21:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Comparing accented strings with TSQL</title>
		<link>http://www.youdidwhatwithtsql.com/comparing-accented-strings-with-tsql/849</link>
		<comments>http://www.youdidwhatwithtsql.com/comparing-accented-strings-with-tsql/849#comments</comments>
		<pubDate>Mon, 02 Aug 2010 20:38:47 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[collations]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/comparing-accented-strings-with-tsql/849</guid>
		<description><![CDATA[Today a colleague was running into some difficulties matching football team names containing accented characters. For example Olympique Alès and Olympique Ales were not matching when he wanted them to. The issue here is all to do with collations. We can use the Latin1_General_CI_AI collation in our queries to force the comparison to ignore accents [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/comparing-accented-strings-with-tsql/849">Comparing accented strings with TSQL</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Today a colleague was running into some difficulties matching football team names containing accented characters. For example <em>Olympique Alès </em>and <em>Olympique Ales</em> were not matching when he wanted them to. The issue here is all to do with <a href="http://msdn.microsoft.com/en-us/library/ms144260.aspx" target="_blank">collations</a>. We can use the <strong>Latin1_General_CI_AI</strong> collation in our queries to force the comparison to ignore accents (AI stands for <em>Accent Insensitive</em>).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p849code8'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8498"><td class="code" id="p849code8"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">DECLARE</span> @string1 <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span>, @string2 <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">SET</span> @string1 <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Olympique Alès'</span>; <span style="color: #008080;">-- With accented e</span>
<span style="color: #0000FF;">SET</span> @string2 <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Olympique Ales'</span>; <span style="color: #008080;">-- Without accented e</span>
&nbsp;
<span style="color: #0000FF;">IF</span> @string1 <span style="color: #808080;">=</span> @string2
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'Strings do not match!'</span>; <span style="color: #008080;">-- This will not print</span>
<span style="color: #0000FF;">END</span>
&nbsp;
<span style="color: #0000FF;">IF</span> @string1 <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AI <span style="color: #808080;">=</span> @string2 <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AI
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'Strings match if we use COLLATE Latin1_General_CI_AI!'</span>; <span style="color: #008080;">-- This will print</span>
<span style="color: #0000FF;">END</span></pre></td></tr></table></div>

<p>Here’s how it works with GROUP BY.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p849code9'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8499"><td class="code" id="p849code9"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">Places</span>
<span style="color: #808080;">&#40;</span>
	Id <span style="color: #0000FF;">INTEGER</span> <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>,<span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span>,
	Place <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>
<span style="color: #808080;">&#41;</span>;
&nbsp;
<span style="color: #008080;">-- Insert some test data</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Places</span> 
<span style="color: #808080;">&#40;</span>
	Place
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">VALUES</span>
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'Olympique Alès'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'Olympique Ales'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'Gazélec Ajaccio'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'Gazelec Ajaccio'</span>
<span style="color: #808080;">&#41;</span>;
&nbsp;
&nbsp;
<span style="color: #0000FF;">SELECT</span> Place, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Places</span>
<span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span> Place;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/group_by_no_collate.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="group by no collate" border="0" alt="group by no collate thumb Comparing accented strings with TSQL" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/group_by_no_collate_thumb.png" width="240" height="126" /></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p849code10'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84910"><td class="code" id="p849code10"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> Place <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AI, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Places</span>
<span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span> Place <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AI;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/group_by_with_collate.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="group by with collate" border="0" alt="group by with collate thumb Comparing accented strings with TSQL" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/group_by_with_collate_thumb.png" width="254" height="89" /></a> </p>
<p>You can also use this with JOINS.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p849code11'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84911"><td class="code" id="p849code11"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- No COLLATE</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Places</span> t1
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> dbo.<span style="color: #202020;">Places</span> t2
	<span style="color: #0000FF;">ON</span> t1.<span style="color: #202020;">Place</span> <span style="color: #808080;">=</span> t2.<span style="color: #202020;">Place</span>;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/join_no_collate.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="join no collate" border="0" alt="join no collate thumb Comparing accented strings with TSQL" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/join_no_collate_thumb.png" width="275" height="137" /></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p849code12'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84912"><td class="code" id="p849code12"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- With COLLATE</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Places</span> t1
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> dbo.<span style="color: #202020;">Places</span> t2
	<span style="color: #0000FF;">ON</span> t1.<span style="color: #202020;">Place</span> <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AI <span style="color: #808080;">=</span> t2.<span style="color: #202020;">Place</span> <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AI;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/join_with_collate.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="join with collate" border="0" alt="join with collate thumb Comparing accented strings with TSQL" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/join_with_collate_thumb.png" width="273" height="225" /></a> </p>
<p>So that’s how you can force strings to match if they contain accented characters. I was using this for a quick data mapping task but be wary of using the COLLATE clause, in any applications or processes, where performance may become an issue. </p>
<p>If you use the COLLATE clause then this will mean the database engine cannot use any index on the referenced column. You could replace the accented characters before inserting them into your database but here’s a solution I prefer using persisted <a href="http://www.youdidwhatwithtsql.com/computed-columns-in-sql-server/377" target="_blank">computed columns</a>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p849code13'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84913"><td class="code" id="p849code13"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Alter Places table. Note we specify the collation</span>
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">Places</span> <span style="color: #0000FF;">ADD</span> CleanPlaceName <span style="color: #0000FF;">AS</span> Place <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AI PERSISTED;
<span style="color: #008080;">-- Index this column!</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">INDEX</span> idx_CleanPlaceName <span style="color: #0000FF;">ON</span> dbo.<span style="color: #202020;">Places</span> <span style="color: #808080;">&#40;</span>CleanPlaceName<span style="color: #808080;">&#41;</span>;
&nbsp;
<span style="color: #008080;">-- Note accents in CleanPlaceName are preserved</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Places</span>
&nbsp;
<span style="color: #008080;">-- No COLLATE needed!</span>
<span style="color: #0000FF;">SELECT</span> CleanPlaceName, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Places</span>
<span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span> CleanPlaceName;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/group_by_no_collate_needed.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="group by no collate needed" border="0" alt="group by no collate needed thumb Comparing accented strings with TSQL" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/group_by_no_collate_needed_thumb.png" width="250" height="102" /></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p849code14'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84914"><td class="code" id="p849code14"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Places</span> t1
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> dbo.<span style="color: #202020;">Places</span> t2
	<span style="color: #0000FF;">ON</span> t1.<span style="color: #202020;">CleanPlaceName</span> <span style="color: #808080;">=</span> t2.<span style="color: #202020;">CleanPlaceName</span>;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/join_no_collate_needed.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="join no collate needed" border="0" alt="join no collate needed thumb Comparing accented strings with TSQL" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/08/join_no_collate_needed_thumb.png" width="463" height="227" /></a> </p>
<p>This solution removes the need to include the COLLATE clause in your queries and keeps the possibility of using indices open!</p>
<p><map name='google_ad_map_849_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/849?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_849_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=849&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fcomparing-accented-strings-with-tsql%2F849' title="Comparing accented strings with TSQL" alt=" Comparing accented strings with TSQL" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/comparing-accented-strings-with-tsql/849">Comparing accented strings with TSQL</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/comparing-accented-strings-with-tsql/849" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/comparing-accented-strings-with-tsql/849/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cannot resolve the collation conflict</title>
		<link>http://www.youdidwhatwithtsql.com/cannot-resolve-the-collation-conflict/176</link>
		<comments>http://www.youdidwhatwithtsql.com/cannot-resolve-the-collation-conflict/176#comments</comments>
		<pubDate>Fri, 12 Jun 2009 17:57:53 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[collations]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/cannot-resolve-the-collation-conflict/176</guid>
		<description><![CDATA[I do a fair bit of work with Linked Servers and cross-database queries&#160; and sometimes come across the following error when joining between databases with different collations; Msg 468, Level 16, State 9, Line 1 Cannot resolve the collation conflict between 'Latin1_General_CI_AS' and 'SQL_Latin1_General_Pref_CP850_CI_AS'; in the equal to operation. To replicate this error run the [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/cannot-resolve-the-collation-conflict/176">Cannot resolve the collation conflict</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I do a fair bit of work with <a href="http://msdn.microsoft.com/en-us/library/ms188279.aspx" target="_blank">Linked Servers</a> and <a href="http://www.sqlservercentral.com/articles/Advanced/designingcrossdatabasequeries/1753/" target="_blank">cross-database queries</a>&#160; and sometimes come across the following error when joining between databases with different <a href="http://msdn.microsoft.com/en-us/library/aa214408(SQL.80).aspx" target="_blank">collations</a>;</p>
<pre>Msg 468, Level 16, State 9, Line 1

Cannot resolve the collation conflict between 'Latin1_General_CI_AS' and 'SQL_Latin1_General_Pref_CP850_CI_AS'; in the equal to operation.</pre>
<p>To replicate this error run the below <a href="http://msdn.microsoft.com/en-us/library/ms189826.aspx" target="_blank">TSQL</a> to create two databases with tables and data.&#160;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p176code19'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p17619"><td class="code" id="p176code19"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Create first database</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">DATABASE</span> database1 <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AS;
GO
<span style="color: #008080;">-- Create second database</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">DATABASE</span> database2 <span style="color: #0000FF;">COLLATE</span> SQL_Latin1_General_Pref_CP850_CI_AS;
GO
&nbsp;
<span style="color: #0000FF;">USE</span> database1;
GO
<span style="color: #008080;">-- Create Customer table in database1</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> Customer
<span style="color: #808080;">&#40;</span>
	CustID <span style="color: #0000FF;">INTEGER</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #0000FF;">CLUSTERED</span>,
	FirstName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	LastName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	DOB <span style="color: #0000FF;">DATETIME</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	StartDate <span style="color: #0000FF;">DATETIME</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">DEFAULT</span> <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>; 
GO
<span style="color: #0000FF;">USE</span> database2;
GO
<span style="color: #008080;">-- Create Customer table in database2</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> Customer
<span style="color: #808080;">&#40;</span>
	CustID <span style="color: #0000FF;">INTEGER</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #0000FF;">CLUSTERED</span>,
	FirstName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	LastName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	DOB <span style="color: #0000FF;">DATETIME</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	StartDate <span style="color: #0000FF;">DATETIME</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">DEFAULT</span> <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>; 
GO
&nbsp;
<span style="color: #0000FF;">USE</span> database1;
GO
<span style="color: #008080;">-- Insert test data</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Customer</span>
<span style="color: #808080;">&#40;</span>
	FirstName,
	LastName,
	DOB
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Joe'</span>, <span style="color: #FF0000;">'Bloggs'</span>, <span style="color: #FF0000;">'1975-01-01 00:00:00'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span><span style="color: #FF0000;">'Dave'</span>, <span style="color: #FF0000;">'Smith'</span>, <span style="color: #FF0000;">'1977-10-11 00:00:00'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span><span style="color: #FF0000;">'Fred'</span>, <span style="color: #FF0000;">'Bloggs'</span>, <span style="color: #FF0000;">'1965-11-28 00:00:00'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span><span style="color: #FF0000;">'Sue'</span>, <span style="color: #FF0000;">'Smith'</span>, <span style="color: #FF0000;">'1974-06-17 00:00:00'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Steve'</span>, <span style="color: #FF0000;">'Smith'</span>, <span style="color: #FF0000;">'1981-07-07 00:00:00'</span>;
GO
<span style="color: #0000FF;">USE</span> database2;
GO
<span style="color: #008080;">-- Insert test data</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Customer</span>
<span style="color: #808080;">&#40;</span>
	FirstName,
	LastName,
	DOB
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Joe'</span>, <span style="color: #FF0000;">'Bloggs'</span>, <span style="color: #FF0000;">'1975-01-01 00:00:00'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span><span style="color: #FF0000;">'Dave'</span>, <span style="color: #FF0000;">'Smith'</span>, <span style="color: #FF0000;">'1977-10-11 00:00:00'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span><span style="color: #FF0000;">'Fred'</span>, <span style="color: #FF0000;">'Bloggs'</span>, <span style="color: #FF0000;">'1965-11-28 00:00:00'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span><span style="color: #FF0000;">'Sue'</span>, <span style="color: #FF0000;">'Smith'</span>, <span style="color: #FF0000;">'1974-06-17 00:00:00'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Steve'</span>, <span style="color: #FF0000;">'Smith'</span>, <span style="color: #FF0000;">'1981-07-07 00:00:00'</span>;
GO</pre></td></tr></table></div>

<p>Run the following query to observe the collation conflict.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p176code20'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p17620"><td class="code" id="p176code20"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Cross-database query causing the collation conflict</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Customer</span> c1
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> database1.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Customer</span> <span style="color: #0000FF;">AS</span> c2
	<span style="color: #0000FF;">ON</span> c1.<span style="color: #202020;">FirstName</span> <span style="color: #808080;">=</span> c2.<span style="color: #202020;">FirstName</span>
<span style="color: #808080;">AND</span> c1.<span style="color: #202020;">LastName</span> <span style="color: #808080;">=</span> c2.<span style="color: #202020;">LastName</span>;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/06/image11.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SQL Server collation conflict" border="0" alt="image thumb11 Cannot resolve the collation conflict" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/06/image-thumb11.png" width="644" height="72" /></a> </p>
<p>You could fix this by changing the collation in one of the databases, i.e.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p176code21'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p17621"><td class="code" id="p176code21"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Set database2 to the same collation as database1</span>
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> database2 <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AS;
<span style="color: #008080;">-- Change VARCHAR columns on our existing tables</span>
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">TABLE</span> Customer <span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">COLUMN</span> FirstName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AS;
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">TABLE</span> Customer <span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">COLUMN</span> LastName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">COLLATE</span> Latin1_General_CI_AS;</pre></td></tr></table></div>

<p>Sometimes you may not want, or be able, to change a database in this way. In these situations you can add <a href="http://msdn.microsoft.com/en-us/library/aa258237(SQL.80).aspx" target="_blank">COLLATE</a> DATABASE_DEFAULT to the JOINS or expressions in your query.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p176code22'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p17622"><td class="code" id="p176code22"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Using COLLATE DATABASE_DEFAULT</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Customer</span> c1
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> database1.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Customer</span> <span style="color: #0000FF;">AS</span> c2
	<span style="color: #0000FF;">ON</span> c1.<span style="color: #202020;">FirstName</span> <span style="color: #808080;">=</span> c2.<span style="color: #202020;">FirstName</span> <span style="color: #0000FF;">COLLATE</span> DATABASE_DEFAULT
<span style="color: #808080;">AND</span> c1.<span style="color: #202020;">LastName</span> <span style="color: #808080;">=</span> c2.<span style="color: #202020;">LastName</span> <span style="color: #0000FF;">COLLATE</span> DATABASE_DEFAULT;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/06/image12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Query using COLLATE DATABASE_DEFAULT" border="0" alt="image thumb12 Cannot resolve the collation conflict" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/06/image-thumb12.png" width="644" height="102" /></a></p>
<p><map name='google_ad_map_176_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/176?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_176_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=176&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fcannot-resolve-the-collation-conflict%2F176' title="Cannot resolve the collation conflict" alt=" Cannot resolve the collation conflict" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/cannot-resolve-the-collation-conflict/176">Cannot resolve the collation conflict</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/cannot-resolve-the-collation-conflict/176" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/cannot-resolve-the-collation-conflict/176/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

