Saturday, 30 April 2016

MSSQL - Add leading zeros (0) to the integer

Watch this example on YouTube

Here I will add up to 20 zeros

SELECT  replicate ( '0', 20- len([CustomerID])) + cast (CustomerID as varchar(50)) as accNum
  FROM [TEST].[dbo].[Customers]

1 comment:

  1. what if you don't want to create a new column? Can this be used to alter the existing CustomerID field?

    ReplyDelete