SP ScriptProblem

  • Hello!

    Having problems with a query(SP) here.

    I was trying to check if a value is NULL (Divide by null), but I can't make it work.

    Here is my code;

    declare @UnitWeight as Real

    set @UnitWeight = 1

    SELECT SUM(FVALUE) as fVal from ITEM

    SET @UnitWeight = fVal //Here I get an error saying: "Invalid column Name 'fVal'

     

    Can anyone help me please


    -Lars

    Please only reply to this newsgroup. All mails would be bounced back.

  • A couple of things....

    Firstly, you most likely don't want @unitweight to be of type real.

    I'd guess that a numeric(n,2) would do the job for you. Real is an imprecise datatype, and is bound to give you rounding errors.

    To the other problem then.

    As the message says, fVal isn't a column name. You can't use it like that.

    You have to do something like;

    declare @unitweight numeric(10,2)

    SELECT @unitweight = SUM(fvalue)

    FROM item

    On the other hand, if all you want to do with this check is to avoid a division by zero error,

    you can also use the ISNULL function on the expression for this purpose.

    eg. if col1 may be null...

    SELECT ISNULL(col1, 1) / SUM(col2)

    FROM ....

    Hope it helps some...

    =;o)

    /Kenneth

  • Try this instead:

    declare @UnitWeight as Real

    SELECT @UnitWeight  = SUM(FVALUE) from ITEM

     

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

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