October 15, 2019 at 12:00 am
Comments posted to this topic are about the item More Computed Column Indexes
October 15, 2019 at 6:27 am
The error message for that isn't quite what I got, and with a little tweaking I could add the index
drop table if exists dbo.MonthlySales;
create table dbo.MonthlySales (
id int identity(1, 1) primary key clustered
, invoiceLine bigint
, SalePrice float)
ALTER TABLE dbo.MonthlySales ADD EstSalePrice AS ROUND(SalePrice, 0) persisted
CREATE INDEX MonthlySales_EstSalePrice ON dbo.MonthlySales (EstSalePrice)
October 15, 2019 at 8:14 am
dammit - I pretty much only use persisted computed columns (we write once and read many)… so my version worked - I took out the persisted and it errored
MVDBA
October 15, 2019 at 9:02 am
None of the answers is correct. You can index a computed column based on a float as long as it is persisted.
October 15, 2019 at 11:26 am
Seldom use float, so have never had to perform this kind of task, so learned something.
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
October 15, 2019 at 1:21 pm
There are two answers that are close but none of them are actually correct. Great question topic though.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 15, 2019 at 4:05 pm
Without persisted, this doesn't work. That was what the question tested, not if you can find a way to index a float column.
October 15, 2019 at 6:22 pm
Without persisted, this doesn't work. That was what the question tested, not if you can find a way to index a float column.
Right, but the "correct" answer states "An error is returned because you cannot index a float field used in a computed column". That is not true. You can index a float field in a computed column, but it must be persisted. I looked at the question and knew right away it would need to be persisted but none of the answers really dealt with that. If it had added "unless it is persisted" to the end of the answer it would be have been more clear.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 15, 2019 at 7:33 pm
I can see the answer as misleading. Edited it.
October 15, 2019 at 8:32 pm
I can see the answer as misleading. Edited it.
I wouldn't say it is misleading but it certainly had me scratching my head. The fix leaves it ambiguous enough to not give it away but also clears it up nicely. Well done as always Steve.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 16, 2019 at 8:13 am
I'm with steve on this - the question wasn't "what do you do to fix this" - it was "what error will occur" - and even though I never use float and if I do a computed column I persist it, steve's question highlighted something that might trip me up... so kudos for the question
MVDBA
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply