Computed Column question

  • With the formula below what does the (1.0) mean?

    (isnull(([UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty],(0.0)))

    thanks

    Erik

    Dam again!

  • ??

    the parens around the 1.0 are superfluous.  actually many of the parens are.  this is equivalent:

    isnull

    ([UnitPrice] * (1.0 - [UnitPriceDiscount]) * [OrderQty], 0.0)

    also coalesce is preferred (by me anyway) over isnull.  coalesce is ansi standard, and can take more than 2 args.  plus isnull behaves strangely when you have args of different types.  for example (from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=82461):

    declare

    @i1 int

    declare

    @v1 bigint

    select

    coalesce(@i1, @v1, 1111111111111111111) --works

    select

    isnull(@i1, 1111111111111111111) --fails

    select

    isnull(@v1, 1111111111111111111) --works

     

    ---------------------------------------
    elsasoft.org

  • The reason why it is 1.0 and not simply 1 is because 1.0 is interpreted as a float by SQL Server.

    For example...

    select 4/3 - returns 1 (an integer as both operands are integers)

    select 4.0/3 - returns 1.33333 (a float as one operand is a float).

    However, I would expect that UnitPriceDiscount is a float/decimal number so the 1.0 is probably not necessary apart from making it clear to the reader that a floating point number will be the result.

  • I will have to make a sticky note of this because I would have never known.

    I have issues with floating points. They are really the only data type that i completely have issues with.

    erik

    Dam again!

  • with those numerous links in your sig, I have a feeling that your posts are some sort of SEO strategy rather than a request for real information. 

    plumbinf.com?  roofinh.com?   you seem to have a business model that depends fat fingering.  good luck with that.

    ---------------------------------------
    elsasoft.org

  • I will remove those from this site if I offend people. I am not here for SEO on this site.

    Fat Fingering on names like plumbinf.com is not wrong because it is generic. Now if that were a company branded name I would be in the wrong. Let me advise you that major players in the tech industry are big time into fat fingering. And this is just an element in a big business model.

    I am on my way to MD and i see BK first i may choose BK. Shall they change the street address for you my friend?

    Dam again!

Viewing 6 posts - 1 through 5 (of 5 total)

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