Dbo.ufnLeadingZeros (function)

From dbscript Online Help
Revision as of 14:36, 3 January 2009 by Bot (talk | contribs) (New page: == wikibot == {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" |- | '''function | dbo.ufnLeadingZeros |- |} <pre> CREATE FUNCTION [dbo].[ufnLeadingZeros]( ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

wikibot

function dbo.ufnLeadingZeros
CREATE FUNCTION [dbo].[ufnLeadingZeros](
    @Value int
) 
RETURNS varchar(8) 
WITH SCHEMABINDING 
AS 
BEGIN
    DECLARE @ReturnValue varchar(8);

    SET @ReturnValue = CONVERT(varchar(8), @Value);
    SET @ReturnValue = REPLICATE('0', 8 - DATALENGTH(@ReturnValue)) + @ReturnValue;

    RETURN (@ReturnValue);
END;