DEV Community

Discussion on: Recreating MYSQL's LPAD Function in SQL Server

Collapse
 
aarone4 profile image
Aaron Reese

It's 11:15pm so maybe I'm missing something...
''''
RIGHT(REPEAT(@padStr,@reqLen) + @origStr, @reqLen)
''''
This will build a dummy string and append the original, than take the Right X chars to give you the left pad

Collapse
 
jamiemcmanus profile image
Jamie Mc Manus

I don't think it replicates the functionality but its close !

The problem is RIGHT will truncate the leftmost characters of the dummy string , while LPad in mysql will truncate the characters on the right of the dummy string but before the original string