We have some data with leading zeros(0) like
0000012345 ,
002009 ,
01256000 . It should be truncated as given below..
0000012345 ->
12345 002009 ->
2009 01256000 ->
1256000 This is routine scenario, so that I have created one function, so that we can use whereever we want...
CREATE FUNCTION DBO.FNC_LeadingZeros_Truncate
(
@String VARCHAR(2000)
) RETURNS VARCHAR(2000) AS
BEGIN
DECLARE @WithZeros VARCHAR(2000)
SELECT @WithZeros = @String
RETURN SUBSTRING(@WithZeros,PATINDEX('%[1-9]%',@WithZeros),LEN(@WithZeros))
END
Execute SELECT DBO.FNC_LeadingZeros_Truncate ('0000023230' ) Result 23230 Cheers