Domain Error

  • Hello.

    Executing the following;

    select power((((12*5.26)-69.26)/100),1.58)

    i got the following error message;

    'Msg 3623, Level 16, State 1, Line 1 Domain Error.'

    Ive read on the web several topics and now I know why de error is coming up, but i dont know how to handle it.

    would yo help me to handle it ?

    thanks in advance.

  • I get a floating point error instead of a domain error, but I'm using SQL 2008 R2, so maybe they just changed the error message for this type of thing.

    By using a fractional exponent of a negative number, you're running into imaginary numbers. SQL Server can't do those for you. You need to move into FORTRAN or some other computer language that's designed for more complex math operations.

    T-SQL isn't the right place to handle this. If you need to, then you'll need to pre-check the numbers, see if they're the type that will cause this error, and only call the function if they won't.

    CREATE PROC dbo.ThisWillErrorOut

    (@BaseNumber_in FLOAT,

    @Power_in FLOAT,

    @Output_out FLOAT)

    AS

    SET NOCOUNT ON;

    SELECT @Output_out = POWER(@BaseNumber_in, @Power_in);

    GO

    DECLARE @BaseNumber FLOAT = (((12 * 5.26) - 69.26) / 100),

    @Power FLOAT = 1.58,

    @Output FLOAT;

    IF @BaseNumber < 0

    AND @Power != FLOOR(@Power)

    BEGIN;

    SELECT NULL;

    END;

    ELSE

    BEGIN;

    EXEC dbo.ThisWillErrorOut @BaseNumber_in = @BaseNumber, @Power_in = @Power, @Output_out = @Output OUTPUT;

    SELECT @Output;

    END;

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • thanks!

    I needed an answer like that.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply