Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Computed Column Divide by Zero?


Computed Column Divide by Zero?

Author
Message
deepak.a
deepak.a
Mr or Mrs. 500
Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)

Group: General Forum Members
Points: 562 Visits: 863
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
tilew-948340
tilew-948340
SSChasing Mays
SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)

Group: General Forum Members
Points: 629 Visits: 2437
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!
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21105 Visits: 18259
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

hakan.winther
hakan.winther
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2702 Visits: 601
Good question, i thought it would happen upon insert, but I didn't realize that it was not persisted.

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


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search