0

Possible Duplicate:
Removing leading zeroes from a field in a SQL statement

In a SQL Server 2008 database I have a string column which I need to select with the leading "0"s removed. E.g. 0023AFF should be returned as 23AFF. Is this possible in T-Sql and how?

Community
  • 1
  • 1
GaussZ
  • 838
  • 10
  • 25

1 Answers1

4

Use PatIndex

declare @s varchar(20)='0023aff'

select substring(@s,PATINDEX('%[^0]%',@s),LEN(@s))
podiluska
  • 50,950
  • 7
  • 98
  • 104