eo
MIS
- Apr 3, 2003
- 809
Hi,
I used SQL Server 2005 to create a view which I want to index. As with most views, I have to name some column names with the "as" operator. This seems to be unacceptable with Indexed views/ schemabinding as I get the following error;
"Synonyms are invalid in a schemabound object or a constraint expression"
Does that mean I will not be able to use indexed views on any views where I have synomyms?
The view code attached:
EO
Hertfordshire, England
I used SQL Server 2005 to create a view which I want to index. As with most views, I have to name some column names with the "as" operator. This seems to be unacceptable with Indexed views/ schemabinding as I get the following error;
"Synonyms are invalid in a schemabound object or a constraint expression"
Does that mean I will not be able to use indexed views on any views where I have synomyms?
The view code attached:
Code:
If OBJECT_ID ('ReportAdhoc.LedgerTran') is not null
Drop view ReportAdhoc.LedgerTran;
GO
CREATE View ReportAdhoc.LedgerTran
WITH SCHEMABINDING
as
Select
Row_Number() over (order by LT.MasterNumber+LT.MasterSequence) as TransactionalLevel
,Cast(LT.MasterNumber+LT.MasterSequence as Varchar (9)) as FK_Policy
,LT.AccountCode
,LT.AccountLongDescription
,LT.AccountMajorTypeCode
,LT.AccountMasterSequence
,LT.AccountMinorTypeCode
,LT.AccountShortDescription
,LT.AccountSubAccountCode
,LT.AllocationStatus
,LT.AuditNumber
,LT.BrokerNameCode
,NP1.ListName as BrokerName
,LT.BusinessSource
,LT.CashJournalTypeCode
,LT.ClaimReference
,LT.Class1Code
,LT.Class1Description
,LT.CompanyNameCode
,NP2.ListName as CompanyName
,LT.ContractApproved
,LT.CreatedByAllocationNumber
,LT.CreditControllerNameCode
,NP3.ListName as CreditControllerName
,LT.CreditRating
,LT.CurrencyCodeACCT
,LT.CurrencyCodeBASE
,LT.CurrencyCodeORIG
,LT.EndorsementEndDate
,LT.EndorsementNumber
,LT.EndorsementStartDate
,LT.EndorsementTypeCode
,LT.EndorsementTypeDescription
,LT.EntryDate
,LT.FinanceAmount
,LT.FinanceControllerNameCode
,NP4.ListName as FinanceControllerName
,LT.FinanceDefaultDate
,LT.FinanceDefaultFlag
,LT.FinanceNotificationDate
,LT.FinanceOverridePct
,LT.FinanceProviderCode
,LT.FinanceProviderDescription
,LT.FinanceRef
,LT.FinanceSettlementDueDate
,LT.FinanceType
,LT.FSAClassification
,LT.GuaranteeingBrokerNameCode
,NP5.ListName as GuaranteeingBrokerName
,LT.InsuredNameCode
,NP6.ListName as InsuredName
,LT.JournalNumber
,LT.JournalType
,LT.JournalTypeText
,LT.LatestAllocationDate
,LT.LatestAllocationNumber
,LT.MasterEndorsementNumber
,LT.MasterKeyStatsLedgerSequence
,LT.MasterKeyType
,LT.MasterNumber
,LT.MasterReference
,LT.MasterSequence
,LT.PreAllocationFlagCode
,LT.ProductCode
,LT.ReportingPeriod
,LT.RIFlag
,LT.StatsHeaderSequence
,LT.StatsLedgerSequence
,LT.StatsPostingSequence
,LT.SubBrokerNameCode
,NP7.ListName as SubBrokerName
,LT.SubPortfolioCode
,LT.SubPortfolioDescription
,LT.TransactionDate
,LT.TransactionDescription
,LT.TransactionEnteredUserCode
,LT.TransactionOriginFlag
,LT.TransactionReference1
,LT.TransactionTypeCode
,LT.UnderwritingBranchNameCode
,NP8.ListName as UnderwritingBranchName
,LT.UnderwritingYear
,isnull(LT.AmtACCT_Clm_Allocated * LB.Split, LT.AmtACCT_Clm_Allocated) as AmtACCT_Clm_Allocated
,isnull(LT.AmtACCT_Clm_Closed * LB.Split, LT.AmtACCT_Clm_Closed) as AmtACCT_Clm_Closed
,isnull(LT.AmtACCT_Clm_Unallocated * LB.Split, LT.AmtACCT_Clm_Unallocated) as AmtACCT_Clm_Unallocated
,isnull(LT.AmtACCT_Csh_Allocated * LB.Split, LT.AmtACCT_Csh_Allocated) as AmtACCT_Csh_Allocated
,isnull(LT.AmtACCT_Csh_Closed * LB.Split, LT.AmtACCT_Csh_Closed) as AmtACCT_Csh_Closed
,isnull(LT.AmtACCT_Csh_Unallocated * LB.Split, LT.AmtACCT_Csh_Unallocated) as AmtACCT_Csh_Unallocated
,isnull(LT.AmtACCT_Jnl_Allocated * LB.Split, LT.AmtACCT_Jnl_Allocated) as AmtACCT_Jnl_Allocated
,isnull(LT.AmtACCT_Jnl_Closed * LB.Split, LT.AmtACCT_Jnl_Closed) as AmtACCT_Jnl_Closed
,isnull(LT.AmtACCT_Jnl_Unallocated * LB.Split, LT.AmtACCT_Jnl_Unallocated) as AmtACCT_Jnl_Unallocated
,isnull(LT.AmtACCT_Prm_Allocated * LB.Split, LT.AmtACCT_Prm_Allocated) as AmtACCT_Prm_Allocated
,isnull(LT.AmtACCT_Prm_Closed * LB.Split, LT.AmtACCT_Prm_Closed) as AmtACCT_Prm_Closed
,isnull(LT.AmtACCT_Prm_Closed_Commission * LB.Split, LT.AmtACCT_Prm_Closed_Commission) as AmtACCT_Prm_Closed_Commission
,isnull(LT.AmtACCT_Prm_Closed_Gross * LB.Split, LT.AmtACCT_Prm_Closed_Gross) as AmtACCT_Prm_Closed_Gross
,isnull(LT.AmtACCT_Prm_Closed_Tax * LB.Split, LT.AmtACCT_Prm_Closed_Tax) as AmtACCT_Prm_Closed_Tax
,isnull(LT.AmtACCT_Prm_Unallocated * LB.Split, LT.AmtACCT_Prm_Unallocated) as AmtACCT_Prm_Unallocated
,isnull(LT.AmtBASE_Clm_Allocated * LB.Split, LT.AmtBASE_Clm_Allocated) as AmtBASE_Clm_Allocated
,isnull(LT.AmtBASE_Clm_Closed * LB.Split, LT.AmtBASE_Clm_Closed) as AmtBASE_Clm_Closed
,isnull(LT.AmtBASE_Clm_Unallocated * LB.Split, LT.AmtBASE_Clm_Unallocated) as AmtBASE_Clm_Unallocated
,isnull(LT.AmtBASE_Csh_Allocated * LB.Split, LT.AmtBASE_Csh_Allocated) as AmtBASE_Csh_Allocated
,isnull(LT.AmtBASE_Csh_Closed * LB.Split, LT.AmtBASE_Csh_Closed) as AmtBASE_Csh_Closed
,isnull(LT.AmtBASE_Csh_Unallocated * LB.Split, LT.AmtBASE_Csh_Unallocated) as AmtBASE_Csh_Unallocated
,isnull(LT.AmtBASE_Jnl_Allocated * LB.Split, LT.AmtBASE_Jnl_Allocated) as AmtBASE_Jnl_Allocated
,isnull(LT.AmtBASE_Jnl_Closed * LB.Split, LT.AmtBASE_Jnl_Closed) as AmtBASE_Jnl_Closed
,isnull(LT.AmtBASE_Jnl_Unallocated * LB.Split, LT.AmtBASE_Jnl_Unallocated) as AmtBASE_Jnl_Unallocated
,isnull(LT.AmtBASE_Prm_Allocated * LB.Split, LT.AmtBASE_Prm_Allocated) as AmtBASE_Prm_Allocated
,isnull(LT.AmtBASE_Prm_Closed * LB.Split, LT.AmtBASE_Prm_Closed) as AmtBASE_Prm_Closed
,isnull(LT.AmtBASE_Prm_Closed_Commission * LB.Split, LT.AmtBASE_Prm_Closed_Commission) as AmtBASE_Prm_Closed_Commission
,isnull(LT.AmtBASE_Prm_Closed_Gross * LB.Split, LT.AmtBASE_Prm_Closed_Gross) as AmtBASE_Prm_Closed_Gross
,isnull(LT.AmtBASE_Prm_Closed_Tax * LB.Split, LT.AmtBASE_Prm_Closed_Tax) as AmtBASE_Prm_Closed_Tax
,isnull(LT.AmtBASE_Prm_Unallocated * LB.Split, LT.AmtBASE_Prm_Unallocated) as AmtBASE_Prm_Unallocated
,isnull(LT.AmtORIG_Clm_Allocated * LB.Split, LT.AmtORIG_Clm_Allocated) as AmtORIG_Clm_Allocated
,isnull(LT.AmtORIG_Clm_Closed * LB.Split, LT.AmtORIG_Clm_Closed) as AmtORIG_Clm_Closed
,isnull(LT.AmtORIG_Clm_Unallocated * LB.Split, LT.AmtORIG_Clm_Unallocated) as AmtORIG_Clm_Unallocated
,isnull(LT.AmtORIG_Csh_Allocated * LB.Split, LT.AmtORIG_Csh_Allocated) as AmtORIG_Csh_Allocated
,isnull(LT.AmtORIG_Csh_Closed * LB.Split, LT.AmtORIG_Csh_Closed) as AmtORIG_Csh_Closed
,isnull(LT.AmtORIG_Csh_Unallocated * LB.Split, LT.AmtORIG_Csh_Unallocated) as AmtORIG_Csh_Unallocated
,isnull(LT.AmtORIG_Jnl_Allocated * LB.Split, LT.AmtORIG_Jnl_Allocated) as AmtORIG_Jnl_Allocated
,isnull(LT.AmtORIG_Jnl_Closed * LB.Split, LT.AmtORIG_Jnl_Closed) as AmtORIG_Jnl_Closed
,isnull(LT.AmtORIG_Jnl_Unallocated * LB.Split, LT.AmtORIG_Jnl_Unallocated) as AmtORIG_Jnl_Unallocated
,isnull(LT.AmtORIG_Prm_Allocated * LB.Split, LT.AmtORIG_Prm_Allocated) as AmtORIG_Prm_Allocated
,isnull(LT.AmtORIG_Prm_Closed * LB.Split, LT.AmtORIG_Prm_Closed) as AmtORIG_Prm_Closed
,isnull(LT.AmtORIG_Prm_Closed_Commission * LB.Split, LT.AmtORIG_Prm_Closed_Commission) as AmtORIG_Prm_Closed_Commission
,isnull(LT.AmtORIG_Prm_Closed_Gross * LB.Split, LT.AmtORIG_Prm_Closed_Gross) as AmtORIG_Prm_Closed_Gross
,isnull(LT.AmtORIG_Prm_Closed_Tax * LB.Split, LT.AmtORIG_Prm_Closed_Tax) as AmtORIG_Prm_Closed_Tax
,isnull(LT.AmtORIG_Prm_Unallocated * LB.Split, LT.AmtORIG_Prm_Unallocated) as AmtORIG_Prm_Unallocated
FROM Reports.LedgerTran LT
LEFT JOIN Reports.LedgerBreakdown LB
on LT.StatsLedgerSequence = LB.StatsLedgerSequence
left join Reports.NameProperties NP1
on LT.BrokerNameCode = NP1.NameCode
left join Reports.NameProperties NP2
on LT.CompanyNameCode = NP2.NameCode
left join Reports.NameProperties NP3
on LT.CreditControllerNameCode = NP3.NameCode
left join Reports.NameProperties NP4
on LT.FinanceControllerNameCode = NP4.NameCode
left join Reports.NameProperties NP5
on LT.GuaranteeingBrokerNameCode = NP5.NameCode
left join Reports.NameProperties NP6
on LT.InsuredNameCode = NP6.NameCode
left join Reports.NameProperties NP7
on LT.SubBrokerNameCode = NP7.NameCode
left join Reports.NameProperties NP8
on LT.UnderwritingBranchNameCode = NP8.NameCode
GO
--CLUSTERED INDEX
CREATE UNIQUE CLUSTERED INDEX IDX_UCI_ADHOC_LEDGERTRAN
ON ReportAdhoc.LedgerTran(MasterNumber);
EO
Hertfordshire, England