SQLServer中查询的数字列前面补0返回指定长度的字符串
SQLServer中查询的数字列前面补0返回指定长度的字符串
SQLServer中查询的数字列前面补0返回指定长度的字符串:
如:
角本如下:
/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP 1000 [ID]
,[SN]
,[Name]
FROM [EduDB].[dbo].[TestTab]
select Right('0123456',SN) from TestTab;
select RIGHT(REPLICATE('0',5)+CAST(SN AS varchar(10)),5) AS 'SN' from TestTab;
select RIGHT('00000000'+CAST(SN as varchar(10)),5) as 'sn' from TestTab
效果如下:
SQLServer中查询的数字列前面补0返回指定长度的字符串
https://www.dearcloud.cn/2014/12/08/20200310-cnblogs-old-posts/20141208-SQLServer中查询的数字列前面补0返回指定长度的字符串/