📜  sql 用零填充 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:06.744000             🧑  作者: Mango

代码示例1
If you want nulls to show as '000' 
It might be an integer -- then you would want

SELECT RIGHT('000'+CAST(field AS VARCHAR(3)),3)

As required by the question this answer only works 
if the length <= 3, if you want something larger you need 
to change the string constant and the two integer constants t
o the width needed. eg '0000' and VARCHAR(4)),4