Hi @Bone_12
Since you are using SUBSTRING function, and I guess the result you could get is '123456', '00123456'.
If you want to get rid of the extra 0 in front of the number, there is a simple solution: Convert the data type of string from VARCHAR/NVARCHAR to INT/BIGINT, so that SQL Sever will automatically ignore the extra 0 in front of the number.
Check this:
Create Table #test (Number varchar(100))
Insert Into #test (Number) Values
('5/123456')
,('5/00123456')
,('5/0000123456')
SELECT CAST(SUBSTRING(Number,CHARINDEX('/',Number,1)+1,LEN(Number))AS BIGINT) New_Number
FROM #test
--Or
SELECT TRY_CAST(RIGHT(Number,LEN(Number)-CHARINDEX('/',Number,1)) AS BIGINT) New_Number
FROM #test
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.