USE [yourDB]
GO
SET ANSI_NULLS ON
GO 100
SET QUOTED_IDENTIFIER ON
GO 1000
ALTER FUNCTION [dbo].[ufnLeadingZeros] (@Value INT)
RETURNS VARCHAR(4)
WITH SCHEMABINDING
AS
BEGIN
DECLARE @ReturnValue VARCHAR(8);
SET @ReturnValue = CONVERT(VARCHAR(4), @Value);
SET @ReturnValue = REPLICATE('0', 4 - DATALENGTH(@ReturnValue)) + @ReturnValue;
RETURN (@ReturnValue);
END;
Date :
2013-07-30 18:00:31
By :
ผ่านมา
No. 7
Guest
ปรับปรุงแก้ไข#NO 6
Code
USE yourDB
GO
SET ANSI_NULLS ON
GO 100
SET QUOTED_IDENTIFIER ON
GO 1000
ALTER FUNCTION [dbo].[ufnLeadingZeros] (@Value INT)
RETURNS VARCHAR(4)
WITH SCHEMABINDING
AS
BEGIN
RETURN RIGHT(REPLICATE('0', 4) + LTRIM(@Value), 4);
END;
Usage: Select [dbo].[ufnLeadingZeros](123) As PadLeft
//Result 0123