How to convert int to char with leading zeros?

后端 未结 17 839
一生所求
一生所求 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:19

    I was wondering, would this be on any use to you?

    declare @val int,@len=800
    select replace(str(@val,@len),' ','0')
    

提交回复
热议问题