Recently I needed a piece of TSQL that would strip leading zeros from a string.
In other words, turn this '0001234' into this: '1234'
I found a clever piece of code, blogging it below. Works pretty well, and it short and simple.
DECLARE
@a
VARCHAR
(10) =
'1234'
@b
'001234'
SELECT
SUBSTRING
(@a, PATINDEX(
'%[^0]%'
, @a+
'.'
), LEN(@a)),
(@b, PATINDEX(
, @b+
), LEN(@b))