Skip to content

Instantly share code, notes, and snippets.

@nordinrahman
Created July 28, 2016 06:01
Show Gist options
  • Save nordinrahman/077bea70bd0870e3c3d2dfa314e20c3e to your computer and use it in GitHub Desktop.
Save nordinrahman/077bea70bd0870e3c3d2dfa314e20c3e to your computer and use it in GitHub Desktop.
Set string to the right of the char variable in SQL
DECLARE @COUNTER INT = 0;
DECLARE @PADDEDCOUNTER NCHAR(6)
WHILE @COUNTER < 100000
BEGIN
SET @COUNTER = @COUNTER + 1
DECLARE @COUNTERSTRING NVARCHAR(6) = CAST(@COUNTER AS NVARCHAR(6));
SET @PADDEDCOUNTER = REPLICATE(N' ', 6-LEN(@COUNTERSTRING)) + @COUNTERSTRING
PRINT '"' + @PADDEDCOUNTER + '"'
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment