SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Remove first character and add trailing zero
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

HelalM
Starting Member

USA
19 Posts

Posted - 10/17/2012 :  19:22:52  Show Profile  Reply with Quote
My data in column A look like:
-0002
00030
-0004
00050

I need to remove the first character '-' when occurs and then add a trailing zero so result is:
00020
00030
00040
00050

Thank You for your help

HM

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1673 Posts

Posted - 10/17/2012 :  19:33:36  Show Profile  Reply with Quote
select
   case when left(ColA, 1) = '-' then right(ColA, len(ColA) - 1) + '0'
   else ColA
   end ColA
from
   MyTable


=================================================
We are far more concerned about the desecration of the flag than we are about the desecration of our land. -Wendell Berry
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/17/2012 :  23:09:18  Show Profile  Reply with Quote
SELECT LEFT(REPLACE(field,'-','')+'0',5) FROM table

if there are no other - characters

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

HelalM
Starting Member

USA
19 Posts

Posted - 10/18/2012 :  13:32:43  Show Profile  Reply with Quote
Awesome...thank you

HM
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/18/2012 :  14:07:27  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000