How to convert int to char with leading zeros?

后端 未结 17 875
一生所求
一生所求 2020-12-12 18:55

I need to convert int datafield to nvarchar with leading zeros

example:

1 convert to \'001\'

867 convert to \'000867\', etc.

thx.


17条回答
  •  忘掉有多难
    2020-12-12 19:07

    Try this: select right('00000' + cast(Your_Field as varchar(5)), 5)

    It will get the result in 5 digits, ex: 00001,...., 01234

提交回复
热议问题