How to Add Leading Zeros in SQL Server 2005

104 72
    • 1). Click the Windows "Start" button and select "All Programs." Click "Microsoft SQL Server," then click "SQL Server Management Studio."

    • 2). Log in to your database, then click the database name in the left panel to activate it. Click "New Query" to open the T-SQL editor.

    • 3). Create the variables. You create a variable to contains the new string after you convert the number to a string. Type the following code in the editor:

      declare @number as varchar(20)

    • 4). Convert the number and assign the converted number to the string:

      set @number = cast(@original as varchar(20))

    • 5). Add leading zeros to the string:

      set @number = '000' + @number

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.