Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234

Computed Column Divide by Zero? Expand / Collapse
Author
Message
Posted Friday, October 15, 2010 6:32 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, January 2, 2014 9:57 AM
Points: 554, 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
Post #1005097
Posted Friday, October 15, 2010 6:47 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, May 15, 2014 8:37 PM
Points: 589, Visits: 2,437
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!
Post #1005650
Posted Monday, October 18, 2010 10:16 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 3:27 PM
Points: 21,631, Visits: 15,289
Thanks for the question.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1006347
Posted Tuesday, August 9, 2011 6:58 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, July 3, 2014 2:45 AM
Points: 2,531, Visits: 536
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
Post #1156801
« Prev Topic | Next Topic »

Add to briefcase «««1234

Permissions Expand / Collapse