I’m trying to create an indexed view and get the following error creating the index:
Cannot create index on view
….’
because column ‘Amount’ that is referenced by the view in the
WHERE or GROUP BY clause is imprecise. Consider eliminating the column
from the view, or altering the column to be precise.
The column in question has a data type of real which I guess is the problem?
What’s the appropriate way of resolving this? Can I do a convert in the view SQL to eliminate the “impreciseness”?
The view SQL is specified below:
EXEC('
CREATE VIEW model.ReceivableBillableParties
WITH SCHEMABINDING
AS
SELECT pf.Id AS Id
, pf.InsuranceId AS InsuranceId
, pf.FinancialInsType AS InsuranceType
, pr.ReceivableId
FROM dbo.Receivables pr
INNER JOIN dbo.Demographics pd ON pd.PersonId = pr.PersonId
INNER JOIN dbo.Appointments ap ON ap.AppointmentId = pr.AppointmentId
INNER JOIN dbo.Financiasl pf ON pf.PersonId = pf.PersonId
INNER JOIN dbo.PracticeInsurers pri ON pri.InsurerId = pf.FinancialInsurerId
WHERE pri.Amount = 0
')
EXEC('
CREATE UNIQUE CLUSTERED INDEX [IX_ReceivableBillableParties]
ON model.ReceivableBillableParties ([Id]);
')
The documentation does indicate that the problem lies with the
realdata type (see Precision Requirements). If you want to use that column in theWHEREclause of your view, and index that view, you’ll need to alter the column to a precise data type (i.e.,DECIMAL(9, 2)).EDIT
This documentation provides a clearer explanation for why this restriction exists. From the section “Deterministic Functions”:
Hope that helps.