2018-05-01发表2021-11-01更新SQL1 分钟读完 (大约117个字)SQL PadLeftSQL PadLeft SQL 123PRINT RIGHT(CAST(REPLICATE('0', LEN(no_start)) + CAST(no_start + (inventory - 1) AS VARCHAR(50)) AS VARCHAR(50)), LEN(no_start))PRINT RIGHT(CAST(REPLICATE('0', LEN('000001')) + CAST('000001' + (50 - 1) AS VARCHAR(50)) AS VARCHAR(50)), LEN('000001')) Result1000050 TestTest Sql 1234567891011121314151617PRINT RIGHT(CAST(REPLICATE('0', LEN('000001')) + CAST('000001' + (50 - 1) AS VARCHAR(50)) AS VARCHAR(50)), LEN('000001'))PRINT REPLICATE('0',5)PRINT REPLICATE('0',5) + 123PRINT REPLICATE('0',5) + '123'PRINT REPLICATE('0',5) + STR(123)PRINT REPLICATE('0',5) + CAST(123 AS varchar(20))PRINT STR(123)PRINT STR(123,5,2)PRINT STR(12345678900) Test Result 12345678000050000001230000012300000 12300000123 123123.0 REF C# PadLeft SQL REPLICATE SQL STR SQL PadLefthttps://blog.jichao.top/2018/05/01/SQL PadLeft/作者Alec.ji发布于2018-05-01更新于2021-11-01许可协议#SQLREPLICATEC#PadLeft