<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Order By Numeric Values Formatted as String</title>
	<atom:link href="http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 17 May 2013 15:26:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Sanjay Monpara</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-366503</link>
		<dc:creator><![CDATA[Sanjay Monpara]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 13:06:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-366503</guid>
		<description><![CDATA[If you want result in numeric order then you can use this code,
SELECT ID,
LEFT(Col1,PATINDEX(&#039;%[^0-9]%&#039;,Col1)-1) &#039;Numeric Character&#039;,
Col1 &#039;Original Character&#039;
FROM MyTable
ORDER BY cast(LEFT(Col1,PATINDEX(&#039;%[^0-9]%&#039;,Col1)-1) as int)
GO

ID	Numeric Character	Original Character
1	1	1one
3	2	2two
2	11	11eleven
4	22	22twentytwo
5	111	111oneeleven]]></description>
		<content:encoded><![CDATA[<p>If you want result in numeric order then you can use this code,<br />
SELECT ID,<br />
LEFT(Col1,PATINDEX(&#8216;%[^0-9]%&#8217;,Col1)-1) &#8216;Numeric Character&#8217;,<br />
Col1 &#8216;Original Character&#8217;<br />
FROM MyTable<br />
ORDER BY cast(LEFT(Col1,PATINDEX(&#8216;%[^0-9]%&#8217;,Col1)-1) as int)<br />
GO</p>
<p>ID	Numeric Character	Original Character<br />
1	1	1one<br />
3	2	2two<br />
2	11	11eleven<br />
4	22	22twentytwo<br />
5	111	111oneeleven</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pareshpatelsql</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-364796</link>
		<dc:creator><![CDATA[pareshpatelsql]]></dc:creator>
		<pubDate>Fri, 26 Oct 2012 07:16:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-364796</guid>
		<description><![CDATA[Very Good]]></description>
		<content:encoded><![CDATA[<p>Very Good</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pareshpatelsql</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-364794</link>
		<dc:creator><![CDATA[pareshpatelsql]]></dc:creator>
		<pubDate>Fri, 26 Oct 2012 07:15:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-364794</guid>
		<description><![CDATA[Very Good.]]></description>
		<content:encoded><![CDATA[<p>Very Good.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Coolmind</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-363476</link>
		<dc:creator><![CDATA[Coolmind]]></dc:creator>
		<pubDate>Tue, 23 Oct 2012 21:27:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-363476</guid>
		<description><![CDATA[Order by Numeric Values formatted as string, then the correct order shouldn&#039;t be like this?

SELECT ID,
Col1 &#039;Original Character&#039;
FROM MyTable
ORDER BY CAST(LEFT(Col1,PATINDEX(&#039;%[^0-9]%&#039;,Col1)-1) AS INT)
GO]]></description>
		<content:encoded><![CDATA[<p>Order by Numeric Values formatted as string, then the correct order shouldn&#8217;t be like this?</p>
<p>SELECT ID,<br />
Col1 &#8216;Original Character&#8217;<br />
FROM MyTable<br />
ORDER BY CAST(LEFT(Col1,PATINDEX(&#8216;%[^0-9]%&#8217;,Col1)-1) AS INT)<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SHRI</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-363450</link>
		<dc:creator><![CDATA[SHRI]]></dc:creator>
		<pubDate>Tue, 23 Oct 2012 20:10:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-363450</guid>
		<description><![CDATA[how to use this function if the number is between the string
Ex: NSE-USD-3Y-SB-OP

....]]></description>
		<content:encoded><![CDATA[<p>how to use this function if the number is between the string<br />
Ex: NSE-USD-3Y-SB-OP</p>
<p>&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harsh</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-363248</link>
		<dc:creator><![CDATA[Harsh]]></dc:creator>
		<pubDate>Tue, 23 Oct 2012 07:34:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-363248</guid>
		<description><![CDATA[Thanks, 
Both solutions will work if string has first part as an int and later part as string.
Minor addition in these scripts can handle strings only has int part(no alphabet characters).
So, One of two limitations will be removed

SELECT ID,
Col1 &#039;Original Character&#039;
FROM MyTable
ORDER BY LEFT(Col1,PATINDEX(&#039;%[^0-9]%&#039;,Col1+&#039;a&#039;)-1)

SELECT ID, Col1 &#039;Original Character&#039; FROM MyTable ORDER BY UNICODE(Col1), PATINDEX(&#039;%[^0-9]%&#039;, Col1+&#039;a&#039;), Col1]]></description>
		<content:encoded><![CDATA[<p>Thanks,<br />
Both solutions will work if string has first part as an int and later part as string.<br />
Minor addition in these scripts can handle strings only has int part(no alphabet characters).<br />
So, One of two limitations will be removed</p>
<p>SELECT ID,<br />
Col1 &#8216;Original Character&#8217;<br />
FROM MyTable<br />
ORDER BY LEFT(Col1,PATINDEX(&#8216;%[^0-9]%&#8217;,Col1+&#8217;a')-1)</p>
<p>SELECT ID, Col1 &#8216;Original Character&#8217; FROM MyTable ORDER BY UNICODE(Col1), PATINDEX(&#8216;%[^0-9]%&#8217;, Col1+&#8217;a'), Col1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eduard Uta</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-363241</link>
		<dc:creator><![CDATA[Eduard Uta]]></dc:creator>
		<pubDate>Tue, 23 Oct 2012 07:28:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-363241</guid>
		<description><![CDATA[Hi,

I also have an alternate solution for your “challenge”:

select ID, Col1 as Original_String, SUBSTRING(Col1, 0, PATINDEX(‘%[a-z]%’, Col1)) as Numeric_Character
from MyTable
order by Numeric_Character

I think it is quite elegant…. SUBSTRING(Col1, 0, PATINDEX(‘%[a-z]%’, Col1))… SUBSTRING returns character data if expr (Col1) is character type (our case here) so the result is ok…

You are doing a great job here!

Thanks,
Eduard U.]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I also have an alternate solution for your “challenge”:</p>
<p>select ID, Col1 as Original_String, SUBSTRING(Col1, 0, PATINDEX(‘%[a-z]%’, Col1)) as Numeric_Character<br />
from MyTable<br />
order by Numeric_Character</p>
<p>I think it is quite elegant…. SUBSTRING(Col1, 0, PATINDEX(‘%[a-z]%’, Col1))… SUBSTRING returns character data if expr (Col1) is character type (our case here) so the result is ok…</p>
<p>You are doing a great job here!</p>
<p>Thanks,<br />
Eduard U.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-363219</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Tue, 23 Oct 2012 06:11:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-363219</guid>
		<description><![CDATA[Super Nice Harsh!]]></description>
		<content:encoded><![CDATA[<p>Super Nice Harsh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harsh</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-363214</link>
		<dc:creator><![CDATA[Harsh]]></dc:creator>
		<pubDate>Tue, 23 Oct 2012 06:01:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-363214</guid>
		<description><![CDATA[Alternate solution:

SELECT ID, Col1 &#039;Original Character&#039; FROM MyTable ORDER BY UNICODE(Col1), PATINDEX(&#039;%[^0-9]%&#039;, Col1), Col1]]></description>
		<content:encoded><![CDATA[<p>Alternate solution:</p>
<p>SELECT ID, Col1 &#8216;Original Character&#8217; FROM MyTable ORDER BY UNICODE(Col1), PATINDEX(&#8216;%[^0-9]%&#8217;, Col1), Col1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Virat Kotharivi</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-363168</link>
		<dc:creator><![CDATA[Virat Kotharivi]]></dc:creator>
		<pubDate>Tue, 23 Oct 2012 02:50:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-363168</guid>
		<description><![CDATA[Superb article. Solution to real time scenario.]]></description>
		<content:encoded><![CDATA[<p>Superb article. Solution to real time scenario.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: paul.k</title>
		<link>http://blog.sqlauthority.com/2012/10/23/sql-server-order-by-numeric-values-formatted-as-string/#comment-363162</link>
		<dc:creator><![CDATA[paul.k]]></dc:creator>
		<pubDate>Tue, 23 Oct 2012 02:33:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21225#comment-363162</guid>
		<description><![CDATA[instead of substring and order it in smaller piece, how about concatenate it and order in bigger one?
 consider:

select * from mytable order by  right(&#039;00000&#039; + mycol,10)]]></description>
		<content:encoded><![CDATA[<p>instead of substring and order it in smaller piece, how about concatenate it and order in bigger one?<br />
 consider:</p>
<p>select * from mytable order by  right(&#8217;00000&#8242; + mycol,10)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
