Computed Column Divide by Zero?

  • Hugo Kornelis (10/15/2010)


    deepak.a (10/15/2010)


    Hugo Kornelis (10/15/2010)


    deepak.a (10/15/2010)


    one more doubt on creating the index on computed columns

    (...)

    in the above Quesries second one (Query 2) thrown on error while creating the index on computed column but the Query 1 and Query 3 not thrown error i'm confused about this

    As implied by the text of the error message, a computed column that SQL Server considers imprecise can not be indexed without first pesisting it. But a computed column that is not imprecies can be persisted.

    All results of calculations with floating point data is considered imprecise, that's the reason you get the error in query 2.

    thanks for your reply hugo , but in query 3 i have used decimal (decimal(18,2))data type for that there s no error thrown

    That's because decimal(18,2) is NOT imprecise, whereas float is.

    Thanks a Lot hugo for the reply

  • Hugo Kornelis (10/15/2010)


    tilew-948340 (10/15/2010)


    Hi Hugo.

    The first time I tried the PERSISTED, I got the divide by zero error AFTER the "show table" wich does not seem to be, as I understand it, what it should be doing. So I tried many "set" option, wich brought me to the "declare" error...

    So, if I put the PERSISTED word, should not the error happend after the "Insert null"?

    Here is the code that I used - if you compare this to the QotD, you'll see that adding PERSISTED at one place is the only modification.

    ...

    If I run this (from SSMS, against SQL Server 2005), I get an error after "Insert Zeroes", and a result set with two rows (one with values; one with NULLs)

    ah! HA! I knew I was doing someting wrong. I was putting the "PERSISTED" after the "QTot AS QF1 + QF2", wich mean nothing for a division by zero. Now, I do understand what "persisted" do!

    Thank you very much!

  • Thanks for the question.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Good question, i thought it would happen upon insert, but I didn't realize that it was not persisted.

    /Håkan Winther
    MCITP:Database Developer 2008
    MCTS: SQL Server 2008, Implementation and Maintenance
    MCSE: Data Platform

Viewing 4 posts - 31 through 33 (of 33 total)

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