Skip to content
 

SQL Server Max Int Value

You are currently browsing comments. If you would like to return to the full story, you can read the full entry here: “SQL Server Max Int Value”.

5 Comments

  1. Subodh says:

    Your example takes lot of time for execution because it has to add 1000 everytime that will result in 2147483000 + 647 iterations which consume lot of time. I have reduced the iteration by using looping

    DECLARE @int int
    DECLARE @div bigint

    SET @int = 0
    SET @div=10000000000
    WHILE 1 = 1
    BEGIN
    BEGIN TRY
    SET @int = @int + @div
    END TRY
    BEGIN CATCH
    IF @div=1
    BREAK
    SET @div=@div/10
    CONTINUE
    END CATCH
    END
    SELECT @int

  2. Raj says:

    For a 4 byte int, if you insert a million records everyday, you can keep doing it more than 5 years ;)

  3. Glen says:

    Extrapolating your exactness on this in negative values – lol

    DECLARE @int int
    SET @int = 0
    WHILE 1 = 1
    BEGIN
    BEGIN TRY
    SET @int = @int – 1000
    END TRY
    BEGIN CATCH
    BEGIN TRY
    SET @int = @int – 1
    END TRY
    BEGIN CATCH
    SELECT @int
    BREAK;
    END CATCH
    END CATCH
    END

    result: -2147483648

    “never argue with fools, they beat you with experience every time”

  4. Glen says:

    Sorry your example needs a slight mod to work with SQL 2005;

    DECLARE @int int
    SET @int = 0
    WHILE 1 = 1
    BEGIN
    BEGIN TRY
    SET @int = @int + 1000
    END TRY
    BEGIN CATCH
    BEGIN TRY
    SET @int = @int + 1
    END TRY
    BEGIN CATCH
    SELECT @int
    BREAK;
    END CATCH
    END CATCH
    END

    result: 2147483647

post a comment OR Post Your Question on our ASK! Community!