tags:

views:

2686

answers:

4

What mysql functions are there (if any) to trim leading zeros from an alphanumeric text field?

Field with value "00345ABC" would need to return "345ABC".

+5  A: 

You are looking for the trim() function.

Alright, here is your example

SELECT TRIM(LEADING '0' FROM myfield) FROM table
Chris Bartow
++ Specifically TRIM(LEADING '0' FROM '000345ANB095')
Tom Ritter
+1  A: 

I believe you'd be best off with this:

SELECT TRIM(LEADING '0' FROM myField)

JustinD
A: 

How can we add preceding zeros to VARCHAR value 0000000008

A: 

simply perfect:

SELECT TRIM(LEADING '0' FROM myfield) FROM table