如何在 T-SQL 中将 int 转换为零填充字符串? [英] How do I convert an int to a zero padded string in T-SQL?

查看:31
本文介绍了如何在 T-SQL 中将 int 转换为零填充字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个值为 1 的 int.如何将该 int 转换为零填充字符串,例如 00000001?

Let's say I have an int with the value of 1. How can I convert that int to a zero padded string, such as 00000001?

推荐答案

Declare @MyInt integer Set @MyInt = 123
Declare @StrLen TinyInt Set @StrLen = 8

Select Replace(Str(@MyInt, @StrLen), ' ' , '0')

这篇关于如何在 T-SQL 中将 int 转换为零填充字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆