Difference between revisions of "Dbo.ufnLeadingZerosfunction"

From dbscript Online Help
Jump to: navigation, search
(New page: == wikibot == {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" |- valign="top" | '''Function | dbo.ufnLeadingZeros |- valign="top" | '''Description | Scalar ...)
 
(No difference)

Latest revision as of 00:07, 24 June 2010

wikibot[edit]

Function dbo.ufnLeadingZeros
Description Scalar function used by the Sales.Customer table to help set the account number.

Source[edit]

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;