<?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; Removing Leading Zeros From Column in Table</title>
	<atom:link href="http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Sat, 25 May 2013 01:31:40 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Eileena</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-428108</link>
		<dc:creator><![CDATA[Eileena]]></dc:creator>
		<pubDate>Tue, 26 Feb 2013 21:59:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-428108</guid>
		<description><![CDATA[Hello, I am a rookie for SQL server, who can tell me why a space is added to &#039;Col1&#039; on Pinal&#039;s solution. I tried some samples it works even without adding space. &quot;SUBSTRING(Col1, PATINDEX(&#039;%[^0 ]%&#039;, Col1 + &#039; &#039;), LEN(Col1))&quot;]]></description>
		<content:encoded><![CDATA[<p>Hello, I am a rookie for SQL server, who can tell me why a space is added to &#8216;Col1&#8242; on Pinal&#8217;s solution. I tried some samples it works even without adding space. &#8220;SUBSTRING(Col1, PATINDEX(&#8216;%[^0 ]%&#8217;, Col1 + &#8216; &#8216;), LEN(Col1))&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samith C Valsalan</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-392973</link>
		<dc:creator><![CDATA[Samith C Valsalan]]></dc:creator>
		<pubDate>Fri, 14 Dec 2012 06:30:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-392973</guid>
		<description><![CDATA[Select cast(replace(col1,&#039; &#039;,&#039;0&#039;) as money)  from Table1]]></description>
		<content:encoded><![CDATA[<p>Select cast(replace(col1,&#8217; &#8216;,&#8217;0&#8242;) as money)  from Table1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liz</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-379045</link>
		<dc:creator><![CDATA[Liz]]></dc:creator>
		<pubDate>Fri, 23 Nov 2012 01:29:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-379045</guid>
		<description><![CDATA[If Col1 contains currency symbols , it will throw exception.]]></description>
		<content:encoded><![CDATA[<p>If Col1 contains currency symbols , it will throw exception.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liz</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-379041</link>
		<dc:creator><![CDATA[Liz]]></dc:creator>
		<pubDate>Fri, 23 Nov 2012 01:14:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-379041</guid>
		<description><![CDATA[In ur case, &#039;00.001&#039; will be &#039;.001&#039;.
Sometimes it should be &#039;0.001&#039;.
How about my script here?

SELECT CASE WHEN ISNUMERIC(REPLACE(Col1,&#039; &#039;,&#039;&#039;)) = 0 THEN Col1
            ELSE CONVERT(varchar,
                      CASE WHEN CHARINDEX(&#039;.&#039;,REPLACE(Col1,&#039; &#039;,&#039;&#039;)) &gt; 0 THEN CAST(REPLACE(Col1,&#039; &#039;,&#039;&#039;) AS float)
                      ELSE CAST(REPLACE(Col1,&#039; &#039;,&#039;&#039;) AS int)
                      END)
            END
FROM   Table1]]></description>
		<content:encoded><![CDATA[<p>In ur case, &#8217;00.001&#8242; will be &#8216;.001&#8242;.<br />
Sometimes it should be &#8217;0.001&#8242;.<br />
How about my script here?</p>
<p>SELECT CASE WHEN ISNUMERIC(REPLACE(Col1,&#8217; &#8216;,&#8221;)) = 0 THEN Col1<br />
            ELSE CONVERT(varchar,<br />
                      CASE WHEN CHARINDEX(&#8216;.&#8217;,REPLACE(Col1,&#8217; &#8216;,&#8221;)) &gt; 0 THEN CAST(REPLACE(Col1,&#8217; &#8216;,&#8221;) AS float)<br />
                      ELSE CAST(REPLACE(Col1,&#8217; &#8216;,&#8221;) AS int)<br />
                      END)<br />
            END<br />
FROM   Table1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harsh</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-378467</link>
		<dc:creator><![CDATA[Harsh]]></dc:creator>
		<pubDate>Thu, 22 Nov 2012 04:42:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-378467</guid>
		<description><![CDATA[Yes, that will cause exception.

Updated solution:

SELECT  
RIGHT(Col1, LEN(Col1+&#039;a&#039;) -PATINDEX(&#039;%[^0 ]%&#039;, Col1 + &#039;a&#039; ))
FROM Table1]]></description>
		<content:encoded><![CDATA[<p>Yes, that will cause exception.</p>
<p>Updated solution:</p>
<p>SELECT<br />
RIGHT(Col1, LEN(Col1+&#8217;a') -PATINDEX(&#8216;%[^0 ]%&#8217;, Col1 + &#8216;a&#8217; ))<br />
FROM Table1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rainmaker</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-378445</link>
		<dc:creator><![CDATA[rainmaker]]></dc:creator>
		<pubDate>Thu, 22 Nov 2012 03:49:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-378445</guid>
		<description><![CDATA[Hi, 
    If data is &#039;   &#039;, use right function will cause exception. 
Because Len(&#039;   &#039;) return 0]]></description>
		<content:encoded><![CDATA[<p>Hi,<br />
    If data is &#8216;   &#8216;, use right function will cause exception.<br />
Because Len(&#8216;   &#8216;) return 0</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; Removing Leading Zeros From Column in Table &#8211; Part 2 &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-378374</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Removing Leading Zeros From Column in Table &#8211; Part 2 &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Thu, 22 Nov 2012 01:30:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-378374</guid>
		<description><![CDATA[[...] I wrote a blog post about Remvoing Leading Zeros from Column In Table. It was a great co-incident that my friend Madhivanan (no need of introduction for him) also post a [...]]]></description>
		<content:encoded><![CDATA[<p>[...] I wrote a blog post about Remvoing Leading Zeros from Column In Table. It was a great co-incident that my friend Madhivanan (no need of introduction for him) also post a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: naveen2cool</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-378048</link>
		<dc:creator><![CDATA[naveen2cool]]></dc:creator>
		<pubDate>Wed, 21 Nov 2012 11:36:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-378048</guid>
		<description><![CDATA[Thanks for pointing out the limitations Pinal and Harsh.]]></description>
		<content:encoded><![CDATA[<p>Thanks for pointing out the limitations Pinal and Harsh.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harsh</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377944</link>
		<dc:creator><![CDATA[Harsh]]></dc:creator>
		<pubDate>Wed, 21 Nov 2012 07:44:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377944</guid>
		<description><![CDATA[And , this solution will not work when no is larger than maximum integer value (2147483647).]]></description>
		<content:encoded><![CDATA[<p>And , this solution will not work when no is larger than maximum integer value (2147483647).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377916</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Wed, 21 Nov 2012 06:56:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377916</guid>
		<description><![CDATA[One more thing above solution will not handle space as well decimal points.]]></description>
		<content:encoded><![CDATA[<p>One more thing above solution will not handle space as well decimal points.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377913</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Wed, 21 Nov 2012 06:48:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377913</guid>
		<description><![CDATA[Harsh - great one buddy!]]></description>
		<content:encoded><![CDATA[<p>Harsh &#8211; great one buddy!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377910</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Wed, 21 Nov 2012 06:44:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377910</guid>
		<description><![CDATA[This will indeed work but if there are alphanumeric character it will not work.

But great solution indeed - it will work in my use case which I wrote in blog post! Good Job!]]></description>
		<content:encoded><![CDATA[<p>This will indeed work but if there are alphanumeric character it will not work.</p>
<p>But great solution indeed &#8211; it will work in my use case which I wrote in blog post! Good Job!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: iamAkashSingh</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377492</link>
		<dc:creator><![CDATA[iamAkashSingh]]></dc:creator>
		<pubDate>Tue, 20 Nov 2012 14:42:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377492</guid>
		<description><![CDATA[Hi,

i have an alternate solution.

Replace(Ltrim(Replace(col1,&#039;0&#039;,&#039; &#039;)),&#039; &#039;,&#039;0&#039;)

Thanks and Regards,
Akash K Singh]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>i have an alternate solution.</p>
<p>Replace(Ltrim(Replace(col1,&#8217;0&#8242;,&#8217; &#8216;)),&#8217; &#8216;,&#8217;0&#8242;)</p>
<p>Thanks and Regards,<br />
Akash K Singh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: naveen2cool</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377186</link>
		<dc:creator><![CDATA[naveen2cool]]></dc:creator>
		<pubDate>Tue, 20 Nov 2012 06:31:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377186</guid>
		<description><![CDATA[I got a similar question when I went for an interview but the question was to remove both the leading and trailing zeros in a string column with numeric charecters. The solution I gave is this

select reverse(convert(int,reverse(convert(int,col1)))) from table1

Please let me know if there is a better solution]]></description>
		<content:encoded><![CDATA[<p>I got a similar question when I went for an interview but the question was to remove both the leading and trailing zeros in a string column with numeric charecters. The solution I gave is this</p>
<p>select reverse(convert(int,reverse(convert(int,col1)))) from table1</p>
<p>Please let me know if there is a better solution</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: naveen2coolNaveen</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377175</link>
		<dc:creator><![CDATA[naveen2coolNaveen]]></dc:creator>
		<pubDate>Tue, 20 Nov 2012 06:27:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377175</guid>
		<description><![CDATA[wonderful. I recently attended an interview for data analyst position and got the same question. It was interesting. But the question was to remove both the leading and trailing zeros from a string column having only numeric charecters.

The answer I gave was 

select reverse(convert(int,reverse(convert(int,col1)))) from table1

The idea is converting a column to int will remove the leading zeros. 

Pinal Sir, please let me know if there can be a beter solution :)]]></description>
		<content:encoded><![CDATA[<p>wonderful. I recently attended an interview for data analyst position and got the same question. It was interesting. But the question was to remove both the leading and trailing zeros from a string column having only numeric charecters.</p>
<p>The answer I gave was </p>
<p>select reverse(convert(int,reverse(convert(int,col1)))) from table1</p>
<p>The idea is converting a column to int will remove the leading zeros. </p>
<p>Pinal Sir, please let me know if there can be a beter solution :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377155</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Tue, 20 Nov 2012 06:09:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377155</guid>
		<description><![CDATA[It means that Find the first position a character in a string which is not 0]]></description>
		<content:encoded><![CDATA[<p>It means that Find the first position a character in a string which is not 0</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377153</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Tue, 20 Nov 2012 06:08:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377153</guid>
		<description><![CDATA[Similar post of mine is http://beyondrelational.com/modules/2/blogs/70/posts/18203/removing-leading-zeroes-in-alpha-numeric-string.aspx]]></description>
		<content:encoded><![CDATA[<p>Similar post of mine is <a href="http://beyondrelational.com/modules/2/blogs/70/posts/18203/removing-leading-zeroes-in-alpha-numeric-string.aspx" rel="nofollow">http://beyondrelational.com/modules/2/blogs/70/posts/18203/removing-leading-zeroes-in-alpha-numeric-string.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ritta Singh</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-377025</link>
		<dc:creator><![CDATA[Ritta Singh]]></dc:creator>
		<pubDate>Tue, 20 Nov 2012 00:58:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-377025</guid>
		<description><![CDATA[^0 means Pattern not like 0
Basically get the first Non 0 or Non Space character(If you see carefully there is a space after 0 in the pattern), take its index position in the string and then using substring, retrieve anything after that.]]></description>
		<content:encoded><![CDATA[<p>^0 means Pattern not like 0<br />
Basically get the first Non 0 or Non Space character(If you see carefully there is a space after 0 in the pattern), take its index position in the string and then using substring, retrieve anything after that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lucazav</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-376808</link>
		<dc:creator><![CDATA[lucazav]]></dc:creator>
		<pubDate>Mon, 19 Nov 2012 15:37:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-376808</guid>
		<description><![CDATA[This is another way to do that:

SELECT
    T.Col1
	, label = CAST(
					CAST(REPLACE(T.Col1, &#039; &#039;, &#039;&#039;) AS FLOAT)
				AS VARCHAR(10))
FROM Table1 AS T

Regards]]></description>
		<content:encoded><![CDATA[<p>This is another way to do that:</p>
<p>SELECT<br />
    T.Col1<br />
	, label = CAST(<br />
					CAST(REPLACE(T.Col1, &#8216; &#8216;, &#8221;) AS FLOAT)<br />
				AS VARCHAR(10))<br />
FROM Table1 AS T</p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kumar</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-376591</link>
		<dc:creator><![CDATA[kumar]]></dc:creator>
		<pubDate>Mon, 19 Nov 2012 09:30:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-376591</guid>
		<description><![CDATA[what does ^0 mean in t- sql]]></description>
		<content:encoded><![CDATA[<p>what does ^0 mean in t- sql</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harsh</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-376426</link>
		<dc:creator><![CDATA[Harsh]]></dc:creator>
		<pubDate>Mon, 19 Nov 2012 05:08:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-376426</guid>
		<description><![CDATA[As mentioned by &#039;rainmaker&#039;, For Zeros &#039;000&#039;, it is not giving proper result.
For this, my suggested solution is:

SELECT
SUBSTRING(Col1, PATINDEX(&#039;%[^0 ]%&#039;, Col1 + &#039;a&#039;), LEN(Col1))
FROM Table1

And for alternate solution , I have used RIGHT function,

SELECT
RIGHT(Col1, LEN(Col1)+1 -PATINDEX(&#039;%[^0 ]%&#039;, Col1 + &#039;a&#039; ))
FROM Table1]]></description>
		<content:encoded><![CDATA[<p>As mentioned by &#8216;rainmaker&#8217;, For Zeros &#8217;000&#8242;, it is not giving proper result.<br />
For this, my suggested solution is:</p>
<p>SELECT<br />
SUBSTRING(Col1, PATINDEX(&#8216;%[^0 ]%&#8217;, Col1 + &#8216;a&#8217;), LEN(Col1))<br />
FROM Table1</p>
<p>And for alternate solution , I have used RIGHT function,</p>
<p>SELECT<br />
RIGHT(Col1, LEN(Col1)+1 -PATINDEX(&#8216;%[^0 ]%&#8217;, Col1 + &#8216;a&#8217; ))<br />
FROM Table1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rainmaker</title>
		<link>http://blog.sqlauthority.com/2012/11/19/sql-server-removing-leading-zeros-from-column-in-table/#comment-376368</link>
		<dc:creator><![CDATA[rainmaker]]></dc:creator>
		<pubDate>Mon, 19 Nov 2012 02:15:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21637#comment-376368</guid>
		<description><![CDATA[Hi,
Should we check the value &#039;000&#039;? PATINDEX will return zero.

SELECT
CASE PATINDEX(&#039;%[^0 ]%&#039;, Col1 + &#039; &#039;) 
WHEN 0 THEN &#039;&#039;
ELSE SUBSTRING(Col1, PATINDEX(&#039;%[^0 ]%&#039;, Col1 + &#039; &#039;), LEN(Col1))
END 
FROM Table1]]></description>
		<content:encoded><![CDATA[<p>Hi,<br />
Should we check the value &#8217;000&#8242;? PATINDEX will return zero.</p>
<p>SELECT<br />
CASE PATINDEX(&#8216;%[^0 ]%&#8217;, Col1 + &#8216; &#8216;)<br />
WHEN 0 THEN &#8221;<br />
ELSE SUBSTRING(Col1, PATINDEX(&#8216;%[^0 ]%&#8217;, Col1 + &#8216; &#8216;), LEN(Col1))<br />
END<br />
FROM Table1</p>
]]></content:encoded>
	</item>
</channel>
</rss>
