• Here is sp_configure with a simple optimization:

    -- Use @configname and try to find the right option.

    -- If there isn't just one, print appropriate diagnostics and return.

    select @configcount = count(*)

    ,@confignameFullName = MAX(name)

    from sys.configurations

    where lower(name) like '%' + @configname + '%'

    and (is_advanced = 0 or @show_advance = 1)

    -- If no option, print an error message.

    if @configcount = 0

    begin

    raiserror (15123,-1,-1,@confignameIn)

    return (1)

    end

    -- If more than one option like @configname, show the duplicates and return.

    if @configcount > 1

    begin

    raiserror (15124,-1,-1,@confignameIn)

    print ' '

    select duplicate_options = name

    from sys.configurations

    where lower(name) like '%' + @configname + '%'

    and (is_advanced = 0 or @show_advance = 1)

    return (1)

    end

    else

    -- There must be exactly one, so get the full name.

    SET @configname = @confignameFullName

    /*

    select @configname = name

    from sys.configurations

    where lower(name) like '%' + @configname + '%'

    and (is_advanced = 0 or @show_advance = 1)

    */