TSQL--INT转换成指定长度字符串
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: GGA
-- Create date: 20131011
-- Description: 将INT值转换成指定长度的字符串,长度不够的在前面补0
-- =============================================
CREATE FUNCTION ufn_ConvertIntToChar
(
@num INT,
@length INT
)
RETURNS VARCHAR(200)
AS
BEGIN
DECLARE @result VARCHAR(200)
SELECT @result=REPLICATE('0',@length-len(CAST(@num AS VARCHAR(200))))+CAST(@num AS VARCHAR(200))
RETURN @result
END
GO