• Bhuvnesh (11/8/2013)


    TheSQLGuru (11/8/2013)


    the engine LIES to SSMS when UDFs are in play.

    please elaborate. Or ANy article reference.

    Below is the UDF:

    CREATE FUNCTION [dbo].[CheckDigit](@vol varchar(50))

    returns int

    as

    begin

    declare @trdx bigint,

    @i int

    select @i = 0,

    @trdx = 0,

    @vol = replace(@vol,'.','')

    if isNumeric(@vol) = 1

    begin

    while len(@vol) > 0

    begin

    if @i in (0,1)

    begin

    select @i = 3

    end

    else if @i = 3

    begin

    select @i = 7

    end

    else if @i = 7

    begin

    select @i = 1

    end

    select @trdx = @trdx + left(@vol,1) * @i

    if LEN(@vol) = 1

    begin

    select @vol = ''

    end

    else

    begin

    select @vol = substring(@vol,2,len(@vol))

    end

    end

    end

    return case when @trdx % 11 = 0 then 1

    when @trdx % 11 = 1 then 0

    else 11 - @trdx % 11

    end

    end