-1

If I have codes stored in sql server database that look something like the following.

000001234560
000012345670
000000123450

How Can i remove all leading zeroes from the start of each code leaving me with

1234560
12345670
123450

Thank you

psycho
  • 1,539
  • 4
  • 20
  • 36

2 Answers2

1

Convert the strings to numbers:

SELECT CONVERT(INT, YourColumn)
FROM YourTable
Tom
  • 7,640
  • 1
  • 23
  • 47
-1

Found the answer through another stackoverflow query here

The code that worked for me was

 SUBSTRING(str_col, PATINDEX('%[^0]%', str_col+'.'), LEN(str_col))

Thanks for your help

Community
  • 1
  • 1
psycho
  • 1,539
  • 4
  • 20
  • 36
  • As your question is a duplicate of the other, don't post the answer from the other question here. there's no need as this question will be closed as a duplicate soon enough. – jpw Mar 03 '15 at 16:26