locked
Returning value with leading zeros RRS feed

  • Question

  • Consider the simple procedure:

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go

    ALTER PROCEDURE [dbo].[ZeroNr]

    AS
    BEGIN 
    DECLARE @sNum nvarchar(50)
    DECLARE @iNum bigint

    SET @iNum = 521868108168
    SET @sNum = CONVERT(varchar(255), @iNum)
    SET @sNum = RIGHT(@sNum, 5)
    --PRINT @sNum
    RETURN @sNum

    END


    Now try it via:
    DECLARE @tst nvarchar(50)
    EXEC @tst = ZeroNr
    SELECT @tst AS NR


    Why is the result 8168 NOT 08168?  Is there a simple way of returning 08168

    Thanks
    Wednesday, February 16, 2011 2:33 PM