SQLServer中查询的数字列前面补0返回指定长度的字符串:
如:
角本如下:
/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP [ID]
,[SN]
,[Name]
FROM [EduDB].[dbo].[TestTab]
select Right('',SN) from TestTab;
select RIGHT(REPLICATE('',)+CAST(SN AS varchar()),) AS 'SN' from TestTab;
select RIGHT(''+CAST(SN as varchar()),) as 'sn' from TestTab
效果如下: