sql 不够七位数 在左侧自动补零,怎么实现?

  1. if object_id('[TB]'is not null drop table [TB]  
  2. create table [TB]([id] int)  
  3. insert [TB]  
  4. select 49999 union all  
  5. select 4565 union all  
  6. select 12362 union all  
  7. select 1111111 union all  
  8. select 232132 union all  
  9. select 2222  
  10. GO  
  11. select right('000000'+ltrim([id]),7) id from [TB]  
  12. id  
  13. --------------  
  14. 0049999  
  15. 0004565  
  16. 0012362  
  17. 1111111  
  18. 0232132  
  19. 0002222  
  20. (6 行受影响)  
posted @ 2012-10-09 11:25  Net-Spider  阅读(260)  评论(0)    收藏  举报