<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Zlatko Michailov : SQL Server</title><link>http://blogs.msdn.com/esql/archive/tags/SQL+Server/default.aspx</link><description>Tags: SQL Server</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Le Roi Est Mort, Vive Le Roi!</title><link>http://blogs.msdn.com/esql/archive/2008/09/08/le-roi-est-mort-vive-le-roi.aspx</link><pubDate>Tue, 09 Sep 2008 09:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8935981</guid><dc:creator>Zlatko Michailov</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/esql/comments/8935981.aspx</comments><wfw:commentRss>http://blogs.msdn.com/esql/commentrss.aspx?PostID=8935981</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN lang=EN style="mso-ansi-language: EN"&gt;&lt;FONT face=Verdana&gt;Now that SQL Server 2008 is out the door, I’m full throttle on my new job. I’m totally excited about the improvement I’m working on, and I can’t wait to start blogging about it (once it’s out of secrecy.) &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN lang=EN style="mso-ansi-language: EN"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN lang=EN style="mso-ansi-language: EN"&gt;&lt;FONT face=Verdana&gt;Today I’m only changing the outlook of my blog to reflect my new &lt;I style="mso-bidi-font-style: normal"&gt;emploi&lt;/I&gt;. Yes, I’ve decided to keep this blog. I actually like the ESQL acronym. It seems to fit anywhere. I realize my blog now looks just like &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/mattn/"&gt;&lt;FONT face=Verdana&gt;Matt Neerincx&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;’, but I really like the sunny picture – we don’t have much of that up here in Seattle. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN lang=EN style="mso-ansi-language: EN"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN lang=EN style="mso-ansi-language: EN"&gt;&lt;FONT face=Verdana&gt;I’ve added links to the &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/sql_protocols/"&gt;&lt;FONT face=Verdana&gt;SQL Server Protocols&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt; team blog and &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/mattn/"&gt;&lt;FONT face=Verdana&gt;Matt Neerincx&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;’ blog. Those are the people with whom I work now. Their knowledge on SQL Server connectivity by far exceeds mine. There is a lot to learn from digging into those blogs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN lang=EN style="mso-ansi-language: EN"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN lang=EN style="mso-ansi-language: EN"&gt;&lt;FONT face=Verdana&gt;While I’m not blogging, I answer questions (a couple per day) at the &lt;/FONT&gt;&lt;A href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=87&amp;amp;SiteID=1"&gt;&lt;FONT face=Verdana&gt;SQL Server Data Access&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt; forum. If something’s bugging you, post it there, we have plenty of smart people watching the forum.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8935981" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/esql/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>The Edm.Length() Canonical Function over SqlClient</title><link>http://blogs.msdn.com/esql/archive/2007/12/19/Length.aspx</link><pubDate>Thu, 20 Dec 2007 10:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6814298</guid><dc:creator>Zlatko Michailov</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/esql/comments/6814298.aspx</comments><wfw:commentRss>http://blogs.msdn.com/esql/commentrss.aspx?PostID=6814298</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;I recently blogged about &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/esql/archive/2007/12/05/EntitySQL_5F00_CanonicalFunctions.aspx"&gt;&lt;FONT face=Verdana color=#0000ff&gt;canonical functions in Entity Framework&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt; and &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/esql/archive/2007/12/14/LEN.aspx"&gt;&lt;FONT face=Verdana&gt;SQL Server’s LEN() function&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;. The purpose of those two posts was to lay out the foundation for this one, and to allow it to be brief and coherent. Please read those two posts before proceeding. &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;If you’ve been using the &lt;SPAN class=MsoSubtleEmphasis&gt;&lt;EM&gt;&lt;FONT color=#808080&gt;Edm.Length()&lt;/FONT&gt;&lt;/EM&gt;&lt;/SPAN&gt; canonical function from the Beta 2 and Beta 3 releases, you may have noticed that it’s behavior (and the T-SQL generated for it), when used against the SqlClient provider, have changed. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;In Beta 2 SqlClient used to generate the following T-SQL for Edm.Length(x):&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #dbe5f1; PADDING-BOTTOM: 1pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div"&gt;
&lt;P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #dbe5f1; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #0000cc; FONT-FAMILY: 'Courier New'"&gt;LEN&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;(x + &lt;SPAN style="COLOR: #c00000"&gt;'.'&lt;/SPAN&gt;) – &lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #0000cc"&gt;LEN&lt;/SPAN&gt;&lt;/B&gt;(&lt;SPAN style="COLOR: #c00000"&gt;'.'&lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;The purpose of generating a non-trivial expression was to compensate for LEN()’s behavior of ignoring trailing spaces by appending a non-blank character. Unfortunately, that approach had one big deficiency – it was returning a wrong result for string values at the 8KB boundary. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;In Beta 3 we investigated the adoption of a different compensating formula, based on the &lt;/FONT&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms173486.aspx"&gt;&lt;FONT face=Verdana&gt;DATALENGTH()&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt; function, but the formula was too complex, and it was returning wrong results over Unicode strings with surrogate characters. Thus we concluded that the provider should not try to alter its server’s behavior, and &lt;SPAN class=MsoSubtleEmphasis&gt;&lt;EM&gt;&lt;FONT color=#808080&gt;we mapped Edm.Length(x) to a plain LEN(x)&lt;/FONT&gt;&lt;/EM&gt;&lt;/SPAN&gt;. You should be aware of that behavior, and design workarounds that suite your specific scenarios. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;Going forward, we’ve requested a new string length function from the T-SQL team – one that accounts for all characters. When, whether, and in what form it will be implemented is still unknown, but we are convinced that’s the right approach to provide a canonical string length behavior in both Entity Framework and SQL Server.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6814298" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/esql/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/esql/archive/tags/Entity+SQL/default.aspx">Entity SQL</category><category domain="http://blogs.msdn.com/esql/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>SQL Server’s LEN() Function</title><link>http://blogs.msdn.com/esql/archive/2007/12/14/LEN.aspx</link><pubDate>Sat, 15 Dec 2007 03:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6773553</guid><dc:creator>Zlatko Michailov</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/esql/comments/6773553.aspx</comments><wfw:commentRss>http://blogs.msdn.com/esql/commentrss.aspx?PostID=6773553</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;There is a peculiarity around the &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;LEN()&lt;/SPAN&gt;&lt;FONT face=Verdana&gt; function in SQL Server that not many people have realized or paid attention to. It’s the treatment of trailing spaces. The &lt;/FONT&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms190329.aspx"&gt;&lt;FONT face=Verdana&gt;documentation&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt; says: &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #dbe5f1; PADDING-BOTTOM: 1pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div"&gt;
&lt;P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #dbe5f1; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt"&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;“&lt;SPAN style="FONT-SIZE: 8.5pt"&gt;Returns the number of characters of the specified string expression, &lt;SPAN style="BACKGROUND: yellow; mso-highlight: yellow"&gt;excluding trailing blanks&lt;/SPAN&gt;.&lt;/SPAN&gt;”&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;(The highlighting is mine.) &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;Indeed&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #dbe5f1; PADDING-BOTTOM: 1pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div"&gt;
&lt;P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #dbe5f1; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: fuchsia"&gt;LEN&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;'abc'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;), &lt;/SPAN&gt;&lt;SPAN style="COLOR: fuchsia"&gt;LEN&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;'abc&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;returns: &lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;3&lt;/U&gt;&lt;/B&gt;&lt;U&gt; &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;3&lt;/B&gt;&lt;/U&gt;, not &lt;U&gt;3&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;12&lt;/U&gt; as most people would expect.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;I tried to deduce the rationale behind this behavior even though that doesn’t change the behavior at all: It must have appeared as a remedy for fixed-length character strings – &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;char&lt;/SPAN&gt;&lt;FONT face=Verdana&gt; and &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;nchar&lt;/SPAN&gt;&lt;FONT face=Verdana&gt;. Since those are always padded with blank spaces to fill up the entire slot, &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;LEN()&lt;/SPAN&gt;&lt;FONT face=Verdana&gt; over values of those types would always return the size of the type, regardless of the value. That would be pretty useless. Unfortunately this behavior has been extended over to variable-length character strings where all characters, including trailing blanks, have a meaning. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;Is SQL Server alone in this? No, there are other database servers with the same behavior. You can try the above query on your server, and see how it treats trailing spaces. What can we do? &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="mso-fareast-font-family: Verdana; mso-bidi-font-family: Verdana"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Verdana&gt;a.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Verdana&gt;If strings like &lt;/FONT&gt;&lt;SPAN style="COLOR: red; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;'abc'&lt;/SPAN&gt;&lt;FONT face=Verdana&gt; and &lt;/FONT&gt;&lt;SPAN style="COLOR: red; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;'abc&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'&lt;/SPAN&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;are equivalent in your application, this behavior is perfect for you. You may eventually consider trimming the trailing spaces explicitly using &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;RTIM() &lt;/SPAN&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="mso-bidi-font-family: 'Courier New'"&gt;to be more explicit.&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="mso-fareast-font-family: Verdana; mso-bidi-font-family: Verdana"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Verdana&gt;b.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Verdana&gt;If you do want to distinguish between those two strings, you should consider appending a special, non-blank, character at the end that you can strip off when you load strings from the database. You should also subtract the number of such special characters from what &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;LEN()&lt;/SPAN&gt;&lt;FONT face=Verdana&gt; returns. If you have strings with corner-case lengths – 4,000 for &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;nvarchar&lt;/SPAN&gt;&lt;FONT face=Verdana&gt; and 8,000 for &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;varchar&lt;/SPAN&gt;&lt;FONT face=Verdana&gt;, you should consider casting values to &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;nvarchar(max)&lt;/SPAN&gt;&lt;FONT face=Verdana&gt; or &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;varchar(max)&lt;/SPAN&gt;&lt;FONT face=Verdana&gt; respectively before appending anything. Otherwise, the characters that exceed the type size limit will be silently lost.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6773553" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/esql/archive/tags/SQL+Server/default.aspx">SQL Server</category></item></channel></rss>