Pages

2013/11/21

[SQL Server] Is this the most simply RPAD and LPAD?

Get 20 charactors and RPAD with zero.
SELECT REPLACE(CONVERT(NCHAR(20), 'SQLServer2014-'), SPACE(1), '0')
-- Result : SQLServer2014-000000
Get 20 charactors and LPAD with zero.
SELECT REPLACE(REVERSE(CONVERT(NCHAR(20), REVERSE('SQLServer2014-'))), SPACE(1), '0')
-- Result :  000000SQLServer2014-
Related Posts Plugin for WordPress, Blogger...