Skip to content

Instantly share code, notes, and snippets.

@tgh0831
Created October 26, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgh0831/976319a745f4bca31aa0a1b0d74c1d74 to your computer and use it in GitHub Desktop.
Save tgh0831/976319a745f4bca31aa0a1b0d74c1d74 to your computer and use it in GitHub Desktop.
Short T-SQL example of formatting a number with leading zeroes.
--When you have a number that needs to be formatted with leading zeroes
DECLARE @idnumber INT= 80253;
SELECT @idnumber AS idnumberint,
RIGHT('000000'+CAST(@idnumber AS VARCHAR), 6) AS idnumbervarchar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment