To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Miscellaneous > Ask an Expert

Ask an Expert Ask our SQL experts the tough questions that have you stumped. Members are limited to one question a week, so ask your questions wisely!

Reply Post New Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-13-2003, 12:19 PM
jumpshift jumpshift is offline
Junior Member
 
Join Date: Jun 2003
Posts: 2
Strip leading zeroes from a string

Hello,

I need to know how to strip leading zeroes from a string. I've seen some examples that work with stripping leading zeroes from a numeric string and several that work stripping from a character string but I have a field that can be both. Two examples are:

00000000001234 should convert to 1234
0000WEB0005678 should convert to WEB0005678

All strings are 14 characters in length.

The following code works for the non-numeric string but not the numeric string:

Code:
SELECT substring(@charValue, patindex('%[a-Z]%',@charValue), len(@charValue) - patindex('%[a-Z]%',@charValue) + 1)
How can I modify it so that it works with both? Any help would be greatly appreciated.
Reply With Quote
  #2  
Old 06-13-2003, 01:38 PM
skhanal skhanal is offline
Experts
 
Join Date: Nov 2002
Location: New Jersey, USA
Posts: 3,644
Try this

SELECT substring(@charValue, patindex('%[a-Z,1-9]%',@charValue), len(@charValue) - patindex('%[a-Z,1-9]%',@charValue) + 1)

Or without the comma

SELECT substring(@charValue, patindex('%[a-Z1-9]%',@charValue), len(@charValue) - patindex('%[a-Z1-9]%',@charValue) + 1)
__________________
http://gotodba.com
Reply With Quote
  #3  
Old 06-13-2003, 01:46 PM
jumpshift jumpshift is offline
Junior Member
 
Join Date: Jun 2003
Posts: 2
Talking

thanks, skhanal! that worked perfectly. i figured it had to be something simple like that. you made my day
Reply With Quote
Reply Post New Thread

Bookmarks

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:02 PM.


DatabaseJournal Recent Articles


 » A Guide to Microsoft SQL Server Replication

 » Introduction to SQL Server Proactive Caching

 » Redmond exploits MySQL uncertainty

 » Oracle Launches Oracle Global Trade Manage...

 » SQL Server 2008 RTM Support Ends April 13,...

Search Database Journal:
 







Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.