------------------------------------------------
-- this script creates 305 custom indexes
-- against the e-auto database
-- updated: 2015-06-08
------------------------------------------------

if not exists(select * from sysindexes where id=object_id('dbo.MTReadingRequestContacts') and name='IX_ZCJ_AccessCode')
create index IX_ZCJ_AccessCode on MTReadingRequestContacts(AccessCode);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARCustomers') and name='IX_ZCJ_Active')
create index IX_ZCJ_Active on ARCustomers(Active);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipments') and name='IX_ZCJ_Active')
create index IX_ZCJ_Active on SCEquipments(Active)
  include(EquipmentID,EquipmentNumber,ModelID,ItemID,SerialNumber,CustomerID,LocationID,Address,Location,Contact,ContactPhone);
go

if not exists(select * from sysindexes where id=object_id('dbo.ShAgents') and name='IX_ZCJ_Active')
create index IX_ZCJ_Active on ShAgents(Active);
go

if not exists(select * from sysindexes where id=object_id('dbo.SHAgentCustomProperties') and name='IX_ZCJ_AgentID_ShAttributeID')
create index IX_ZCJ_AgentID_ShAttributeID on SHAgentCustomProperties(AgentID,ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.CBJournal') and name='IX_ZCJ_Amount')
create index IX_ZCJ_Amount on CBJournal(Amount);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportLabors') and name='IX_ZCJ_Amount')
create index IX_ZCJ_Amount on SCReportLabors(Amount);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetails') and name='IX_ZCJ_Amount')
create index IX_ZCJ_Amount on SOFulfillDetails(Amount)
  include(FulfillID,ItemID,Cost);
go

if not exists(select * from sysindexes where id=object_id('dbo.APPayments') and name='IX_ZCJ_AppliedID')
create index IX_ZCJ_AppliedID on APPayments(AppliedID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceipts') and name='IX_ZCJ_AppliedID')
create index IX_ZCJ_AppliedID on ARReceipts(AppliedID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportLabors') and name='IX_ZCJ_ArrivalDate')
create index IX_ZCJ_ArrivalDate on SCReportLabors(ArrivalDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQReportLabors') and name='IX_ZCJ_ArrivalDate_DepartureDate_DispatchID')
create index IX_ZCJ_ArrivalDate_DepartureDate_DispatchID on SCQReportLabors(ArrivalDate,DepartureDate,DispatchID);
go

if not exists(select * from sysindexes where id=object_id('dbo.GLJournalDetails') and name='IX_ZCJ_BalanceSheetGroupID')
create index IX_ZCJ_BalanceSheetGroupID on GLJournalDetails(BalanceSheetGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingContracts') and name='IX_ZCJ_BaseFromDate')
create index IX_ZCJ_BaseFromDate on SCBillingContracts(BaseFromDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingContractBaseCycleCharges') and name='IX_ZCJ_BaseFromDate_BaseToDate')
create index IX_ZCJ_BaseFromDate_BaseToDate on SCBillingContractBaseCycleCharges(BaseFromDate,BaseToDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.LdBaseTables') and name='IX_ZCJ_BaseID')
create index IX_ZCJ_BaseID on LdBaseTables(BaseID);
go

if not exists(select * from sysindexes where id=object_id('dbo.LdBaseColumns') and name='IX_ZCJ_BaseID_IDColumn')
create index IX_ZCJ_BaseID_IDColumn on LdBaseColumns(BaseID,IDColumn);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingContracts') and name='IX_ZCJ_BaseToDate')
create index IX_ZCJ_BaseToDate on SCBillingContracts(BaseToDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrders') and name='IX_ZCJ_BaseTypeID')
create index IX_ZCJ_BaseTypeID on SOOrders(BaseTypeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrders') and name='IX_ZCJ_BaseTypeID_Inc')
create index IX_ZCJ_BaseTypeID_Inc on POOrders(BaseTypeID)
  include(POID,PONumber,VendorID,Date,Description,ReqDate,JobID,PurchaserID,ShipToName,Total,UnReceived,ApprovedByID,Locked,Revised,BranchID,RemitBranchID,NoteFlag,OrderTypeID,StatusID,DetailStatusID,ReturnDetailStatusID,SendMethodID,SendStatusID,VendorConfirmationNumber,NoteCount);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICTransferOrders') and name='IX_ZCJ_Batch')
create index IX_ZCJ_Batch on ICTransferOrders(Batch);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICTransfers') and name='IX_ZCJ_Batch')
create index IX_ZCJ_Batch on ICTransfers(Batch);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOPickets') and name='IX_ZCJ_Batch')
create index IX_ZCJ_Batch on SOPickets(Batch);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_BeginMeterDisplay')
create index IX_ZCJ_BeginMeterDisplay on SCBillingMeters(BeginMeterDisplay);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_BeginMeterReadingID')
create index IX_ZCJ_BeginMeterReadingID on SCBillingMeters(BeginMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQBillingMeters') and name='IX_ZCJ_BeginMeterReadingID')
create index IX_ZCJ_BeginMeterReadingID on SCQBillingMeters(BeginMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContracts') and name='IX_ZCJ_Bill')
create index IX_ZCJ_Bill on SCContracts(Bill);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetails') and name='IX_ZCJ_Bill')
create index IX_ZCJ_Bill on SOFulfillDetails(Bill);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_BillCodeID')
create index IX_ZCJ_BillCodeID on SCCalls(BillCodeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_BillingEquipmentID')
create index IX_ZCJ_BillingEquipmentID on SCBillingMeters(BillingEquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQBillingMeters') and name='IX_ZCJ_BillingEquipmentID')
create index IX_ZCJ_BillingEquipmentID on SCQBillingMeters(BillingEquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQBillingEquipmentBaseCycleCharges') and name='IX_ZCJ_BillingID')
create index IX_ZCJ_BillingID on SCQBillingEquipmentBaseCycleCharges(BillingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_BillingMeterDisplay')
create index IX_ZCJ_BillingMeterDisplay on SCBillingMeters(BeginMeterDisplay);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingOverages') and name='IX_ZCJ_BillingMeterGroupID')
create index IX_ZCJ_BillingMeterGroupID on SCBillingOverages(BillingMeterGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingOvgCharges') and name='IX_ZCJ_BillingMeterGroupID')
create index IX_ZCJ_BillingMeterGroupID on SCBillingOvgCharges(BillingMeterGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_BillingMeterID')
create index IX_ZCJ_BillingMeterID on SCBillingMeters(BillingMeterID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARCustomers') and name='IX_ZCJ_BillToID')
create index IX_ZCJ_BillToID on ARCustomers(BillToID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_BillToID')
create index IX_ZCJ_BillToID on SCCalls(BillToID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReports') and name='IX_ZCJ_BillToID')
create index IX_ZCJ_BillToID on SCReports(BillToID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICInventory') and name='IX_ZCJ_BinID')
create index IX_ZCJ_BinID on ICInventory(BinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICSerialNumbers') and name='IX_ZCJ_BinID')
create index IX_ZCJ_BinID on ICSerialNumbers(BinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.GLJournalDetails') and name='IX_ZCJ_BranchID')
create index IX_ZCJ_BranchID on GLJournalDetails(BranchID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_CallBackID')
create index IX_ZCJ_CallBackID on SCCalls(CallBackCallID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_CallerContactID')
create index IX_ZCJ_CallerContactID on SCCalls(CallerContactID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQReportLabors') and name='IX_ZCJ_CallID')
create index IX_ZCJ_CallID on SCQReportLabors(CallID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQReportMeterReadings') and name='IX_ZCJ_CallID')
create index IX_ZCJ_CallID on SCQReportMeterReadings(CallID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCDispatchHistory') and name='IX_ZCJ_CallID_Inc')
create index IX_ZCJ_CallID_Inc on SCDispatchHistory(CallID)
  include(DispatchHistoryID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceiptDetailBins') and name='IX_ZCJ_CallMaterialBinID')
create index IX_ZCJ_CallMaterialBinID on POReceiptDetailBins(CallMaterialBinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_CallOrder')
create index IX_ZCJ_CallOrder on SCCalls(CallOrder);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentSubcomponents') and name='IX_ZCJ_ChildEquipmentID')
create index IX_ZCJ_ChildEquipmentID on SCEquipmentSubcomponents(ChildEquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentSubcomponents') and name='IX_ZCJ_ChildItemID')
create index IX_ZCJ_ChildItemID on SCEquipmentSubcomponents(ChildItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_CloseDate')
create index IX_ZCJ_CloseDate on SCCalls(CloseDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReports') and name='IX_ZCJ_CloseDate')
create index IX_ZCJ_CloseDate on SCReports(CloseDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentHistory') and name='IX_ZCJ_ConditionID')
create index IX_ZCJ_ConditionID on SCEquipmentHistory(ConditionID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrderDetails') and name='IX_ZCJ_ConfigQuoteDetailID')
create index IX_ZCJ_ConfigQuoteDetailID on SOOrderDetails(ConfigQuoteDetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingEquipments') and name='IX_ZCJ_ContractDetailID')
create index IX_ZCJ_ContractDetailID on SCBillingEquipments(ContractDetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_ContractID')
create index IX_ZCJ_ContractID on SCCalls(ContractID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetails') and name='IX_ZCJ_ContractID')
create index IX_ZCJ_ContractID on SCContractDetails(ContractID)
  include(ContractDetailID,EndDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQReports') and name='IX_ZCJ_ContractID')
create index IX_ZCJ_ContractID on SCQReports(ContractID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrderDetails') and name='IX_ZCJ_ContractID')
create index IX_ZCJ_ContractID on SOOrderDetails(ContractID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractMeterGroups') and name='IX_ZCJ_ContractID_ApplyToExpiration_Inc')
create index IX_ZCJ_ContractID_ApplyToExpiration_Inc on SCContractMeterGroups(ContractID,ApplyToExpiration)
  include(ContractMeterGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractCustomProperties') and name='IX_ZCJ_ContractID_ShAttributeID')
create index IX_ZCJ_ContractID_ShAttributeID on SCContractCustomProperties(ContractID,ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContracts') and name='IX_ZCJ_ContractMajor_ContractMinor')
create index IX_ZCJ_ContractMajor_ContractMinor on SCContracts(ContractMajor,ContractMinor);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeterGroups') and name='IX_ZCJ_ContractMeterGroupID')
create index IX_ZCJ_ContractMeterGroupID on SCBillingMeterGroups(ContractMeterGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetailMeters') and name='IX_ZCJ_ContractMeterGroupID')
create index IX_ZCJ_ContractMeterGroupID on SCContractDetailMeters(ContractMeterGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContracts') and name='IX_ZCJ_ContractStatusID')
create index IX_ZCJ_ContractStatusID on SCContracts(ContractStatusID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARInvoiceDetails') and name='IX_ZCJ_CostAppliedGLID')
create index IX_ZCJ_CostAppliedGLID on ARInvoiceDetails(CostAppliedGLID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICLedger') and name='IX_ZCJ_CostPoolID')
create index IX_ZCJ_CostPoolID on ICLedger(CostPoolID);
go

if not exists(select * from sysindexes where id=object_id('dbo.APVouchers') and name='IX_ZCJ_CreateDate')
create index IX_ZCJ_CreateDate on APVouchers(CreateDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICLedger') and name='IX_ZCJ_CreateDate')
create index IX_ZCJ_CreateDate on ICLedger(CreateDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICTransfers') and name='IX_ZCJ_CreateDate')
create index IX_ZCJ_CreateDate on ICTransfers(CreateDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadings') and name='IX_ZCJ_CreateDate')
create index IX_ZCJ_CreateDate on MTMeterReadings(CreateDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrders') and name='IX_ZCJ_CreateDate')
create index IX_ZCJ_CreateDate on POOrders(CreateDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportMaterials') and name='IX_ZCJ_CreateDate')
create index IX_ZCJ_CreateDate on SCReportMaterials(CreateDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReports') and name='IX_ZCJ_CreateDate')
create index IX_ZCJ_CreateDate on SCReports(CreateDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICLedger') and name='IX_ZCJ_CreatorID')
create index IX_ZCJ_CreatorID on ICLedger(CreatorID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_CreatorID')
create index IX_ZCJ_CreatorID on SCCalls(CreatorID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrders') and name='IX_ZCJ_CreatorID_CreateDate')
create index IX_ZCJ_CreatorID_CreateDate on SOOrders(CreatorID,CreateDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.APVoucherDetails') and name='IX_ZCJ_CustomerID')
create index IX_ZCJ_CustomerID on APVoucherDetails(CustomerID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARCustomerContact') and name='IX_ZCJ_CustomerID')
create index IX_ZCJ_CustomerID on ARCustomerContact(CustomerID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARCustomerCustomProperties') and name='IX_ZCJ_CustomerID')
create index IX_ZCJ_CustomerID on ARCustomerCustomProperties(CustomerID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceipts') and name='IX_ZCJ_CustomerID')
create index IX_ZCJ_CustomerID on ARReceipts(CustomerID);
go

if not exists(select * from sysindexes where id=object_id('dbo.GLJournalDetails') and name='IX_ZCJ_CustomerID')
create index IX_ZCJ_CustomerID on GLJournalDetails(CustomerID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICSalesServiceLedger') and name='IX_ZCJ_CustomerID')
create index IX_ZCJ_CustomerID on ICSalesServiceLedger(CustomerID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportBillGroups') and name='IX_ZCJ_CustomerID')
create index IX_ZCJ_CustomerID on SCReportBillGroups(CustomerID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCWorkOrders') and name='IX_ZCJ_CustomerID')
create index IX_ZCJ_CustomerID on SCWorkOrders(CustomerID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARCustomers') and name='IX_ZCJ_CustomPriceLevelID_EnableCustomPricing')
create index IX_ZCJ_CustomPriceLevelID_EnableCustomPricing on ARCustomers(CustomPriceLevelID,EnableCustomPricing);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceipts') and name='IX_ZCJ_Date')
create index IX_ZCJ_Date on ARReceipts(Date);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICSalesServiceLedger') and name='IX_ZCJ_Date')
create index IX_ZCJ_Date on ICSalesServiceLedger(Date);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_Date_Status_Inc')
create index IX_ZCJ_Date_Status_Inc on SCCalls(Date,Status)
  include(CallID,WorkOrderID,CustomerID,BillToID,CallTypeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceipts') and name='IX_ZCJ_Date_Unvouchered')
create index IX_ZCJ_Date_Unvouchered on POReceipts(Date,UnVouchered);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentProfileHistory') and name='IX_ZCJ_DefaultMeterID')
create index IX_ZCJ_DefaultMeterID on SCEquipmentProfileHistory(DefaultMeterID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipments') and name='IX_ZCJ_DefaultMeterID')
create index IX_ZCJ_DefaultMeterID on SCEquipments(DefaultMeterID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportLabors') and name='IX_ZCJ_DepartureDate')
create index IX_ZCJ_DepartureDate on SCReportLabors(DepartureDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportLabors') and name='IX_ZCJ_DeptID')
create index IX_ZCJ_DeptID on SCReportLabors(DeptID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICModels') and name='IX_ZCJ_Description')
create index IX_ZCJ_Description on ICModels(Description);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrderDetails') and name='IX_ZCJ_DetailID')
create index IX_ZCJ_DetailID on SOOrderDetails(DetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportLabors') and name='IX_ZCJ_DispatchDate')
create index IX_ZCJ_DispatchDate on SCReportLabors(DispatchDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQReportLabors') and name='IX_ZCJ_DispatchID')
create index IX_ZCJ_DispatchID on SCQReportLabors(DispatchID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQBillingMeters') and name='IX_ZCJ_DistBaseAmount')
create index IX_ZCJ_DistBaseAmount on SCQBillingMeters(DistBaseAmount);
go

if not exists(select * from sysindexes where id=object_id('dbo.GLJournalDetails') and name='IX_ZCJ_DivisionID')
create index IX_ZCJ_DivisionID on GLJournalDetails(DivisionID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SHDocumentQueue') and name='IX_ZCJ_DocumentID')
create index IX_ZCJ_DocumentID on SHDocumentQueue(DocumentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetails') and name='IX_ZCJ_EndDate')
create index IX_ZCJ_EndDate on SCContractDetails(EndDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetails') and name='IX_ZCJ_EndMeterReadingGroupID')
create index IX_ZCJ_EndMeterReadingGroupID on SCContractDetails(EndMeterReadingGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_EndMeterReadingID')
create index IX_ZCJ_EndMeterReadingID on SCBillingMeters(EndMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQBillingMeters') and name='IX_ZCJ_EndMeterReadingID')
create index IX_ZCJ_EndMeterReadingID on SCQBillingMeters(EndMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportLabors') and name='IX_ZCJ_EndOdometer')
create index IX_ZCJ_EndOdometer on SCReportLabors(EndOdometer);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadingGroups') and name='IX_ZCJ_EquipmentID')
create index IX_ZCJ_EquipmentID on MTMeterReadingGroups(EquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingEquipments') and name='IX_ZCJ_EquipmentID')
create index IX_ZCJ_EquipmentID on SCBillingEquipments(EquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_EquipmentID')
create index IX_ZCJ_EquipmentID on SCBillingMeters(EquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetails') and name='IX_ZCJ_EquipmentID')
create index IX_ZCJ_EquipmentID on SCContractDetails(EquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractLeaseDetails') and name='IX_ZCJ_EquipmentID')
create index IX_ZCJ_EquipmentID on SCContractLeaseDetails(EquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentHistory') and name='IX_ZCJ_EquipmentID')
create index IX_ZCJ_EquipmentID on SCEquipmentHistory(EquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetails') and name='IX_ZCJ_EquipmentID')
create index IX_ZCJ_EquipmentID on SOFulfillDetails(EquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrderDetails') and name='IX_ZCJ_EquipmentID')
create index IX_ZCJ_EquipmentID on SOOrderDetails(EquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentCustomProperties') and name='IX_ZCJ_EquipmentID_ShAttributeID')
create unique index IX_ZCJ_EquipmentID_ShAttributeID on SCEquipmentCustomProperties(EquipmentID,ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentProfileHistory') and name='IX_ZCJ_EquipmentNumber')
create index IX_ZCJ_EquipmentNumber on SCEquipmentProfileHistory(EquipmentNumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReports') and name='IX_ZCJ_EquipSerialNumber')
create index IX_ZCJ_EquipSerialNumber on SCReports(EquipSerialNumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetailMeters') and name='IX_ZCJ_ExpEndMeterReadingID')
create index IX_ZCJ_ExpEndMeterReadingID on SCContractDetailMeters(ExpEndMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetailMeters') and name='IX_ZCJ_ExpStartMeterReadingID')
create index IX_ZCJ_ExpStartMeterReadingID on SCContractDetailMeters(ExpStartMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetailMeters') and name='IX_ZCJ_FirstBilledMeterReadingID')
create index IX_ZCJ_FirstBilledMeterReadingID on SCContractDetailMeters(FirstBilledMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetailBins') and name='IX_ZCJ_FulfillID_DetailID')
create index IX_ZCJ_FulfillID_DetailID on SOFulfillDetailBins(FulfillID,DetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.APVoucherDetails') and name='IX_ZCJ_GLID')
create index IX_ZCJ_GLID on APVoucherDetails(GLID)
  include(VoucherID,Amount,ContractID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportLabors') and name='IX_ZCJ_GLID')
create index IX_ZCJ_GLID on SCReportLabors(GLID);
go

if not exists(select * from sysindexes where id=object_id('dbo.CBRegister') and name='IX_ZCJ_GLID_Cleared_Inc')
create index IX_ZCJ_GLID_Cleared_Inc on CBRegister(GLID,Cleared)
  include(Amount);
go

if not exists(select * from sysindexes where id=object_id('dbo.GLJournalDetails') and name='IX_ZCJ_GLID_DeptID')
create index IX_ZCJ_GLID_DeptID on GLJournalDetails(GLID,DeptID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipments') and name='IX_ZCJ_InstallDate')
create index IX_ZCJ_InstallDate on SCEquipments(InstallDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceiptDetails') and name='IX_ZCJ_InvoiceID')
create index IX_ZCJ_InvoiceID on ARReceiptDetails(InvoiceID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICSalesServiceLedger') and name='IX_ZCJ_InvoiceID')
create index IX_ZCJ_InvoiceID on ICSalesServiceLedger(InvoiceID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingContractMiscCharges') and name='IX_ZCJ_InvoiceID')
create index IX_ZCJ_InvoiceID on SCBillingContractMiscCharges(InvoiceID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeterGroups') and name='IX_ZCJ_InvoiceID')
create index IX_ZCJ_InvoiceID on SCBillingMeterGroups(InvoiceID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetails') and name='IX_ZCJ_InvoiceID')
create index IX_ZCJ_InvoiceID on SOFulfillDetails(InvoiceID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeterGroups') and name='IX_ZCJ_InvoiceID_ContractDetailID')
create index IX_ZCJ_InvoiceID_ContractDetailID on SCBillingMeterGroups(InvoiceID,ContractDetailID)
  include(BillingMeterGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingContracts') and name='IX_ZCJ_InvoiceID_ContractDetailID_ContractID')
create index IX_ZCJ_InvoiceID_ContractDetailID_ContractID on SCBillingContracts(InvoiceID,ContractDetailID,ContractID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingEquipments') and name='IX_ZCJ_InvoiceID_Inc')
create index IX_ZCJ_InvoiceID_Inc on SCBillingEquipments(InvoiceID)
  include(ContractDetailID,EquipmentID,BillingEquipmentID,EquipmentInstance);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadings') and name='IX_ZCJ_IsEstimate')
create index IX_ZCJ_IsEstimate on MTMeterReadings(IsEstimate);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadings') and name='IX_ZCJ_IsOverEstimate')
create index IX_ZCJ_IsOverEstimate on MTMeterReadings(IsOverEstimate);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrderDetails') and name='IX_ZCJ_IsRTVReturn')
create index IX_ZCJ_IsRTVReturn on POOrderDetails(IsRTVReturn);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadings') and name='IX_ZCJ_IsValid')
create index IX_ZCJ_IsValid on MTMeterReadings(IsValid);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadings') and name='IX_ZCJ_IsValidForBilling')
create index IX_ZCJ_IsValidForBilling on MTMeterReadings(IsValidForBilling);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICCostPoolItems') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on ICCostPoolItems(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICItemCustomProperties') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on ICItemCustomProperties(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICPhysicalInventory') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on ICPhysicalInventory(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICSalesServiceLedgerDetails') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on ICSalesServiceLedgerDetails(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceiptDetailCosts') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on POReceiptDetailCosts(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POVoucherDetailCosts') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on POVoucherDetailCosts(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentBuildDetails') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on SCEquipmentBuildDetails(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentProfileHistory') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on SCEquipmentProfileHistory(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetails') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on SOFulfillDetails(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOPicketDetails') and name='IX_ZCJ_ItemID')
create index IX_ZCJ_ItemID on SOPicketDetails(ItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrderDetailBins') and name='IX_ZCJ_ItemID_StockTypeID')
create index IX_ZCJ_ItemID_StockTypeID on POOrderDetailBins(ItemID,StockTypeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICItemVendorMfgNumbers') and name='IX_ZCJ_ItemID_VendorID')
create index IX_ZCJ_ItemID_VendorID on ICItemVendorMfgNumbers(ItemID,VendorID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrderDetailBins') and name='IX_ZCJ_ItemID_WarehouseID_BinID')
create index IX_ZCJ_ItemID_WarehouseID_BinID on SOOrderDetailBins(ItemID,WarehouseID,BinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.GLJournalDetails') and name='IX_ZCJ_JobID')
create index IX_ZCJ_JobID on GLJournalDetails(JobID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrders') and name='IX_ZCJ_JobID')
create index IX_ZCJ_JobID on POOrders(JobID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetailMeters') and name='IX_ZCJ_LastBilledMeterReadingID')
create index IX_ZCJ_LastBilledMeterReadingID on SCContractDetailMeters(LastBilledMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQBillingMeters') and name='IX_ZCJ_LastBilledMeterReadingID')
create index IX_ZCJ_LastBilledMeterReadingID on SCQBillingMeters(LastBilledMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetails') and name='IX_ZCJ_LastUpdate')
create index IX_ZCJ_LastUpdate on SCContractDetails(LastUpdate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportLabors') and name='IX_ZCJ_LastUpdate')
create index IX_ZCJ_LastUpdate on SCReportLabors(LastUpdate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingEquipments') and name='IX_ZCJ_LeaseBalanceSheetGroupID')
create index IX_ZCJ_LeaseBalanceSheetGroupID on SCBillingEquipments(LeaseBalanceSheetGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrderDetailBins') and name='IX_ZCJ_LinkedTransactionNumber')
create index IX_ZCJ_LinkedTransactionNumber on POOrderDetailBins(LinkedTransactionNumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReservations') and name='IX_ZCJ_LinkedTransactionNumber')
create index IX_ZCJ_LinkedTransactionNumber on POReservations(LinkedTransactionNumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.ShTrackingConfigLinks') and name='IX_ZCJ_LinkID_ShTrackingGroupID')
create index IX_ZCJ_LinkID_ShTrackingGroupID on ShTrackingConfigLinks(LinkID,ShTrackingGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARCustomers') and name='IX_ZCJ_LocationID')
create index IX_ZCJ_LocationID on ARCustomers(LocationID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARInvoices') and name='IX_ZCJ_LocationID')
create index IX_ZCJ_LocationID on ARInvoices(LocationID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingEquipments') and name='IX_ZCJ_LocationID')
create index IX_ZCJ_LocationID on SCBillingEquipments(LocationID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipments') and name='IX_ZCJ_LocationID')
create index IX_ZCJ_LocationID on SCEquipments(LocationID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReports') and name='IX_ZCJ_LocationID')
create index IX_ZCJ_LocationID on SCReports(LocationID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrders') and name='IX_ZCJ_LocationID')
create index IX_ZCJ_LocationID on SOOrders(LocationID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetails') and name='IX_ZCJ_LocationID_SyncLocationAddress')
create index IX_ZCJ_LocationID_SyncLocationAddress on SCContractDetails(LocationID,SyncLocationAddress);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICModels') and name='IX_ZCJ_MakeID_Active')
create index IX_ZCJ_MakeID_Active on ICModels(MakeID,Active);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICMakeCustomProperties') and name='IX_ZCJ_MakeID_ShAttributeID')
create index IX_ZCJ_MakeID_ShAttributeID on ICMakeCustomProperties(MakeID,ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_MasterCallID')
create index IX_ZCJ_MasterCallID on SCCalls(MasterCallID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARAPReceivablePayableApplications') and name='IX_ZCJ_MasterReceivablePayableID')
create index IX_ZCJ_MasterReceivablePayableID on ARAPReceivablePayableApplications(MasterReceivablePayableID);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadings') and name='IX_ZCJ_MeterID')
create index IX_ZCJ_MeterID on MTMeterReadings(MeterID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_MeterID')
create index IX_ZCJ_MeterID on SCBillingMeters(MeterID)
  include(EndMeterDisplay,EndMeterActual,EndMeterDate,BillingEquipmentID,EndMeterReadingIsEstimate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetailMeters') and name='IX_ZCJ_MeterID')
create index IX_ZCJ_MeterID on SCContractDetailMeters(MeterID)
  include(ContractDetailID,FirstBilledMeterReadingDate,FirstBilledMeterReadingActual,LastBilledMeterReadingID,LastBilledMeterReadingDate,LastBilledMeterReadingActual);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadings') and name='IX_ZCJ_MeterReadingGroupID')
create index IX_ZCJ_MeterReadingGroupID on MTMeterReadings(MeterReadingGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReports') and name='IX_ZCJ_MeterReadingGroupID')
create index IX_ZCJ_MeterReadingGroupID on SCReports(MeterReadingGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ShAttributeValues') and name='IX_ZCJ_MeterReadingGroupID')
create index IX_ZCJ_MeterReadingGroupID on ShAttributeValues(MeterReadingGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_MeterType')
create index IX_ZCJ_MeterType on SCBillingMeters(MeterType);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICItemVendorMfgNumbers') and name='IX_ZCJ_MfgNumber')
create index IX_ZCJ_MfgNumber on ICItemVendorMfgNumbers(MfgNumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICItemVendors') and name='IX_ZCJ_MfgNumber')
create index IX_ZCJ_MfgNumber on ICItemVendors(MfgNumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICModels') and name='IX_ZCJ_ModelCategoryID_Inc')
create index IX_ZCJ_ModelCategoryID_Inc on ICModels(ModelCategoryID)
  include(ModelID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICItems') and name='IX_ZCJ_ModelID')
create index IX_ZCJ_ModelID on ICItems(ModelID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICModelCustomProperties') and name='IX_ZCJ_ModelID')
create index IX_ZCJ_ModelID on ICModelCustomProperties(ModelID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentProfileHistory') and name='IX_ZCJ_MostRecentDefaultMeterReadingID')
create index IX_ZCJ_MostRecentDefaultMeterReadingID on SCEquipmentProfileHistory(MostRecentDefaultMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipments') and name='IX_ZCJ_MostRecentDefaultMeterReadingID')
create index IX_ZCJ_MostRecentDefaultMeterReadingID on SCEquipments(MostRecentDefaultMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentProfileHistory') and name='IX_ZCJ_MostRecentHostDefaultMeterReadingID')
create index IX_ZCJ_MostRecentHostDefaultMeterReadingID on SCEquipmentProfileHistory(MostRecentHostDefaultMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeters') and name='IX_ZCJ_MostRecentMeterReadingID')
create index IX_ZCJ_MostRecentMeterReadingID on MTMeters(MostRecentMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadings') and name='IX_ZCJ_NewlyPosted')
create index IX_ZCJ_NewlyPosted on MTMeterReadings(NewlyPosted);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCallNoteDetails') and name='IX_ZCJ_NoteDetailID_TypeID')
create index IX_ZCJ_NoteDetailID_TypeID on SCCallNoteDetails(TypeID)
  include(NoteDetailID,NoteID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_NoteID')
create index IX_ZCJ_NoteID on SCCalls(NoteID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContracts') and name='IX_ZCJ_NoteID')
create index IX_ZCJ_NoteID on SCContracts(NoteID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipments') and name='IX_ZCJ_NoteID')
create index IX_ZCJ_NoteID on SCEquipments(NoteID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCWorkOrders') and name='IX_ZCJ_NoteID')
create index IX_ZCJ_NoteID on SCWorkOrders(NoteID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ShAgents') and name='IX_ZCJ_NoteID')
create index IX_ZCJ_NoteID on ShAgents(NoteID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfills') and name='IX_ZCJ_NoteID')
create index IX_ZCJ_NoteID on SOFulfills(NoteID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrders') and name='IX_ZCJ_NoteID')
create index IX_ZCJ_NoteID on SOOrders(NoteID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrders') and name='IX_ZCJ_OnHold')
create index IX_ZCJ_OnHold on SOOrders(OnHold);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_OnHoldCodeID')
create index IX_ZCJ_OnHoldCodeID on SCCalls(OnHoldCodeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingContracts') and name='IX_ZCJ_OverageFromDate')
create index IX_ZCJ_OverageFromDate on SCBillingContracts(OverageFromDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingContracts') and name='IX_ZCJ_OverageToDate')
create index IX_ZCJ_OverageToDate on SCBillingContracts(OverageToDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadings') and name='IX_ZCJ_OverriddenByID')
create index IX_ZCJ_OverriddenByID on MTMeterReadings(OverriddenByID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentSubcomponents') and name='IX_ZCJ_ParentEquipmentID')
create index IX_ZCJ_ParentEquipmentID on SCEquipmentSubcomponents(ParentEquipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipments') and name='IX_ZCJ_ParentID')
create index IX_ZCJ_ParentID on SCEquipments(ParentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceipts') and name='IX_ZCJ_Period')
create index IX_ZCJ_Period on ARReceipts(Period);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfills') and name='IX_ZCJ_Period')
create index IX_ZCJ_Period on SOFulfills(Period);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICPhysicalInventory') and name='IX_ZCJ_PhysicalInventoryListID')
create index IX_ZCJ_PhysicalInventoryListID on ICPhysicalInventory(PhysicalInventoryListID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICTransferDetails') and name='IX_ZCJ_PODetailBinID')
create index IX_ZCJ_PODetailBinID on ICTransferDetails(PODetailBinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceiptDetailBins') and name='IX_ZCJ_PODetailBinID')
create index IX_ZCJ_PODetailBinID on POReceiptDetailBins(PODetailBinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrderCustomProperties') and name='IX_ZCJ_POID_ShAttributeID')
create index IX_ZCJ_POID_ShAttributeID on POOrderCustomProperties(POID,ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrders') and name='IX_ZCJ_POMajor')
create index IX_ZCJ_POMajor on POOrders(POMajor);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrderDetailBins') and name='IX_ZCJ_POOrderDetailBins_POID_DetailID')
create index IX_ZCJ_POOrderDetailBins_POID_DetailID on POOrderDetailBins(POID,DetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceiptDetails') and name='IX_ZCJ_POReceiptDetailID')
create index IX_ZCJ_POReceiptDetailID on POReceiptDetails(POReceiptDetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICPhysicalInventory') and name='IX_ZCJ_Posted')
create index IX_ZCJ_Posted on ICPhysicalInventory(Posted);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportBillGroups') and name='IX_ZCJ_PostID_VoidID')
create index IX_ZCJ_PostID_VoidID on SCReportBillGroups(PostID,VoidID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ShAgents') and name='IX_ZCJ_PrefFullName')
create index IX_ZCJ_PrefFullName on ShAgents(PrefFullName);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceiptDetails') and name='IX_ZCJ_Price')
create index IX_ZCJ_Price on POReceiptDetails(Price);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetails') and name='IX_ZCJ_Price')
create index IX_ZCJ_Price on SOFulfillDetails(Price);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceiptDetails') and name='IX_ZCJ_PurchaseAmount')
create index IX_ZCJ_PurchaseAmount on POReceiptDetails(PurchaseAmount);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeterGroups') and name='IX_ZCJ_QID')
create index IX_ZCJ_QID on SCBillingMeterGroups(QID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICLedger') and name='IX_ZCJ_Quantity')
create index IX_ZCJ_Quantity on ICLedger(Quantity);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICPhysicalInventory') and name='IX_ZCJ_QuantityCounted')
create index IX_ZCJ_QuantityCounted on ICPhysicalInventory(QuantityCounted);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrderDetailBins') and name='IX_ZCJ_Quantity_BackOrdered')
create index IX_ZCJ_Quantity_BackOrdered on SOOrderDetailBins(Quantity,BackOrdered);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadingGroups') and name='IX_ZCJ_ReadingDate')
create index IX_ZCJ_ReadingDate on MTMeterReadingGroups(ReadingDate);
go

if not exists(select * from sysindexes where id=object_id('dbo.POVoucherDetails') and name='IX_ZCJ_ReceiptID')
create index IX_ZCJ_ReceiptID on POVoucherDetails(ReceiptID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceiptDetailBins') and name='IX_ZCJ_ReceiptID_DetailID')
create index IX_ZCJ_ReceiptID_DetailID on POReceiptDetailBins(ReceiptID,DetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceiptDetailCosts') and name='IX_ZCJ_ReceiptID_DetailID')
create index IX_ZCJ_ReceiptID_DetailID on POReceiptDetailCosts(ReceiptID,DetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceipts') and name='IX_ZCJ_ReceiptNumber')
create index IX_ZCJ_ReceiptNumber on ARReceipts(ReceiptNumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICLedger') and name='IX_ZCJ_Reference')
create index IX_ZCJ_Reference on ICLedger(Reference);
go

if not exists(select * from sysindexes where id=object_id('dbo.MTMeterReadingGroups') and name='IX_ZCJ_Reference')
create index IX_ZCJ_Reference on MTMeterReadingGroups(Reference);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICItemRelatedItems') and name='IX_ZCJ_RelatedItemID')
create index IX_ZCJ_RelatedItemID on ICItemRelatedItems(RelatedItemID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICSalesServiceLedger') and name='IX_ZCJ_ReportBillGroupID')
create index IX_ZCJ_ReportBillGroupID on ICSalesServiceLedger(ReportBillGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReports') and name='IX_ZCJ_ReportBillGroupID')
create index IX_ZCJ_ReportBillGroupID on SCReports(ReportBillGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportBillGroups') and name='IX_ZCJ_ReportBillGroupNumber')
create index IX_ZCJ_ReportBillGroupNumber on SCReportBillGroups(ReportBillGroupNumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportMaterialBins') and name='IX_ZCJ_ReportID_DetailID')
create index IX_ZCJ_ReportID_DetailID on SCReportMaterialBins(ReportID,DetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportMaterialBins') and name='IX_ZCJ_ReportMaterialBinID')
create index IX_ZCJ_ReportMaterialBinID on SCReportMaterialBins(ReportMaterialBinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.RPUserReportParamDetails') and name='IX_ZCJ_ReportParamDetailID_UserReportParamID_Inc')
create index IX_ZCJ_ReportParamDetailID_UserReportParamID_Inc on RPUserReportParamDetails(ReportParamDetailID,UserReportParamID)
  include(Value);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCCalls') and name='IX_ZCJ_RescheduledCallID')
create index IX_ZCJ_RescheduledCallID on SCCalls(RescheduledCallID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrders') and name='IX_ZCJ_ReturnWarehouseID')
create index IX_ZCJ_ReturnWarehouseID on POOrders(ReturnWarehouseID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICTransferOrders') and name='IX_ZCJ_RTSourceTechnicianID_TOID')
create index IX_ZCJ_RTSourceTechnicianID_TOID on ICTransferOrders(RTSourceTechnicianID)
  include(TOID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCQBillingMeters') and name='IX_ZCJ_SCContractDetailID')
create index IX_ZCJ_SCContractDetailID on SCQBillingMeters(SCContractDetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentProfileHistory') and name='IX_ZCJ_SerialNumber')
create index IX_ZCJ_SerialNumber on SCEquipmentProfileHistory(SerialNumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentProfileHistory') and name='IX_ZCJ_SerialNumberID')
create index IX_ZCJ_SerialNumberID on SCEquipmentProfileHistory(SerialNumberID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipments') and name='IX_ZCJ_SerialNumberID')
create index IX_ZCJ_SerialNumberID on SCEquipments(SerialNumberID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARCustomerCustomProperties') and name='IX_ZCJ_ShAttributeID')
create index IX_ZCJ_ShAttributeID on ARCustomerCustomProperties(ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICItemCustomProperties') and name='IX_ZCJ_ShAttributeID')
create index IX_ZCJ_ShAttributeID on ICItemCustomProperties(ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICModelCustomProperties') and name='IX_ZCJ_ShAttributeID')
create index IX_ZCJ_ShAttributeID on ICModelCustomProperties(ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ShAttributeValues') and name='IX_ZCJ_ShAttributeID')
create index IX_ZCJ_ShAttributeID on ShAttributeValues(ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ShTrackingConfigAttributes') and name='IX_ZCJ_ShAttributeID')
create index IX_ZCJ_ShAttributeID on ShTrackingConfigAttributes(ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetails') and name='IX_ZCJ_ShipmentID')
create index IX_ZCJ_ShipmentID on SOFulfillDetails(ShipmentID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICSalesServiceLedger') and name='IX_ZCJ_ShipToID')
create index IX_ZCJ_ShipToID on ICSalesServiceLedger(ShipToID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCReportBillGroups') and name='IX_ZCJ_ShipToID')
create index IX_ZCJ_ShipToID on SCReportBillGroups(ShipToID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCWorkOrders') and name='IX_ZCJ_ShipToID')
create index IX_ZCJ_ShipToID on SCWorkOrders(ShipToID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOShipments') and name='IX_ZCJ_ShipToID')
create index IX_ZCJ_ShipToID on SOShipments(ShipToID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipments') and name='IX_ZCJ_ShTrackingConfigID')
create index IX_ZCJ_ShTrackingConfigID on SCEquipments(ShTrackingConfigID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentHistory') and name='IX_ZCJ_ShTrackingValueGroupID')
create index IX_ZCJ_ShTrackingValueGroupID on SCEquipmentHistory(ShTrackingValueGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ShAttributeValues') and name='IX_ZCJ_ShTrackingValueGroupID')
create index IX_ZCJ_ShTrackingValueGroupID on ShAttributeValues(ShTrackingValueGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POReceiptDetailBins') and name='IX_ZCJ_SODetailBinID')
create index IX_ZCJ_SODetailBinID on POReceiptDetailBins(SODetailBinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetailBins') and name='IX_ZCJ_SODetailBinID')
create index IX_ZCJ_SODetailBinID on SOFulfillDetailBins(SODetailBinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfillDetails') and name='IX_ZCJ_SOID')
create index IX_ZCJ_SOID on SOFulfillDetails(SOID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfills') and name='IX_ZCJ_SOID')
create index IX_ZCJ_SOID on SOFulfills(SOID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrderDetailBins') and name='IX_ZCJ_SOID')
create index IX_ZCJ_SOID on SOOrderDetailBins(SOID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrderDetails') and name='IX_ZCJ_SOID')
create index IX_ZCJ_SOID on SOOrderDetails(SOID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrderCustomProperties') and name='IX_ZCJ_SOID_ShAttributeID')
create index IX_ZCJ_SOID_ShAttributeID on SOOrderCustomProperties(SOID,ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOFulfills') and name='IX_ZCJ_SONumber')
create index IX_ZCJ_SONumber on SOFulfills(SONumber);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOShipments') and name='IX_ZCJ_SOShipments_FulFillID_Freight')
create index IX_ZCJ_SOShipments_FulFillID_Freight on SOShipments(FulFillID)
  include(Freight);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCContractDetails') and name='IX_ZCJ_StartMeterReadingGroupID')
create index IX_ZCJ_StartMeterReadingGroupID on SCContractDetails(StartMeterReadingGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOPickets') and name='IX_ZCJ_Status')
create index IX_ZCJ_Status on SOPickets(Status);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCEquipmentHistory') and name='IX_ZCJ_StatusID')
create index IX_ZCJ_StatusID on SCEquipmentHistory(StatusID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrders') and name='IX_ZCJ_StatusID')
create index IX_ZCJ_StatusID on SOOrders(StatusID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POOrderDetails') and name='IX_ZCJ_Stocked')
create index IX_ZCJ_Stocked on POOrderDetails(Stocked);
go

if not exists(select * from sysindexes where id=object_id('dbo.APPayments') and name='IX_ZCJ_SubType')
create index IX_ZCJ_SubType on APPayments(SubType);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceipts') and name='IX_ZCJ_SubType')
create index IX_ZCJ_SubType on ARReceipts(SubType);
go

if not exists(select * from sysindexes where id=object_id('dbo.LdBaseTables') and name='IX_ZCJ_TableName_Master_DisplayName_BaseID')
create index IX_ZCJ_TableName_Master_DisplayName_BaseID on LdBaseTables(TableName,Master,DisplayName,BaseID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICTransferDetails') and name='IX_ZCJ_TOID_ToDetailID')
create index IX_ZCJ_TOID_ToDetailID on ICTransferDetails(TOID,TODetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.APVouchers') and name='IX_ZCJ_Total')
create index IX_ZCJ_Total on APVouchers(Total);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARHInvoices') and name='IX_ZCJ_Total')
create index IX_ZCJ_Total on ARHInvoices(Total);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARInvoices') and name='IX_ZCJ_Total')
create index IX_ZCJ_Total on ARInvoices(Total);
go

if not exists(select * from sysindexes where id=object_id('dbo.SOOrders') and name='IX_ZCJ_Total')
create index IX_ZCJ_Total on SOOrders(Total);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICTransferOrderNoteDetails') and name='IX_ZCJ_TO_NoteDetailID_TypeID')
create index IX_ZCJ_TO_NoteDetailID_TypeID on ICTransferOrderNoteDetails(TypeID)
  include(NoteDetailID,NoteID);
go

if not exists(select * from sysindexes where id=object_id('dbo.GLJournal') and name='IX_ZCJ_TransactionTypeID')
create index IX_ZCJ_TransactionTypeID on GLJournal(TransactionTypeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICLedger') and name='IX_ZCJ_TransactionTypeID_Inc')
create index IX_ZCJ_TransactionTypeID_Inc on ICLedger(TransactionTypeID)
  include(ItemID,Date);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICTransferDetailBins') and name='IX_ZCJ_TransferDetailBinID')
create index IX_ZCJ_TransferDetailBinID on ICTransferDetailBins(TransferDetailBinID);
go

if not exists(select * from sysindexes where id=object_id('dbo.APPayments') and name='IX_ZCJ_Type')
create index IX_ZCJ_Type on APPayments(Type);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARInvoices') and name='IX_ZCJ_Type')
create index IX_ZCJ_Type on ARInvoices(Type);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceipts') and name='IX_ZCJ_Type')
create index IX_ZCJ_Type on ARReceipts(Type);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICItems') and name='IX_ZCJ_UMID')
create index IX_ZCJ_UMID on ICItems(UMID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceipts') and name='IX_ZCJ_Unapplied')
create index IX_ZCJ_Unapplied on ARReceipts(Unapplied);
go

if not exists(select * from sysindexes where id=object_id('dbo.ShAgents') and name='IX_ZCJ_UserID')
create index IX_ZCJ_UserID on ShAgents(UserID);
go

if not exists(select * from sysindexes where id=object_id('dbo.APVendorCustomProperties') and name='IX_ZCJ_VendorID_ShAttributeID')
create index IX_ZCJ_VendorID_ShAttributeID on APVendorCustomProperties(VendorID,ShAttributeID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARInvoices') and name='IX_ZCJ_Void')
create index IX_ZCJ_Void on ARInvoices(Void);
go

if not exists(select * from sysindexes where id=object_id('dbo.APPayments') and name='IX_ZCJ_VoidID')
create index IX_ZCJ_VoidID on APPayments(VoidID);
go

if not exists(select * from sysindexes where id=object_id('dbo.APVouchers') and name='IX_ZCJ_VoidID')
create index IX_ZCJ_VoidID on APVouchers(VoidID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARInvoices') and name='IX_ZCJ_VoidID')
create index IX_ZCJ_VoidID on ARInvoices(VoidID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ARReceipts') and name='IX_ZCJ_VoidID')
create index IX_ZCJ_VoidID on ARReceipts(VoidID);
go

if not exists(select * from sysindexes where id=object_id('dbo.CBJournal') and name='IX_ZCJ_VoidID')
create index IX_ZCJ_VoidID on CBJournal(VoidID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICTransfers') and name='IX_ZCJ_VoidID')
create index IX_ZCJ_VoidID on ICTransfers(VoidID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_Void_BeginMeterDisplay_Inc')
create index IX_ZCJ_Void_BeginMeterDisplay_Inc on SCBillingMeters(Void,BeginMeterDisplay)
  include(BillingMeterGroupID);
go

if not exists(select * from sysindexes where id=object_id('dbo.SCBillingMeters') and name='IX_ZCJ_Void_Inc')
create index IX_ZCJ_Void_Inc on SCBillingMeters(Void)
  include(MeterID,EndMeterReadingID);
go

if not exists(select * from sysindexes where id=object_id('dbo.POVoucherDetailCosts') and name='IX_ZCJ_VoucherID_DetailID')
create index IX_ZCJ_VoucherID_DetailID on POVoucherDetailCosts(VoucherID,DetailID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICInventory') and name='IX_ZCJ_WarehouseID')
create index IX_ZCJ_WarehouseID on ICInventory(WarehouseID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICLedger') and name='IX_ZCJ_WarehouseID')
create index IX_ZCJ_WarehouseID on ICLedger(WarehouseID);
go

if not exists(select * from sysindexes where id=object_id('dbo.ICWarehouseCustomProperties') and name='IX_ZCJ_WarehouseID_ShAttributeID')
create index IX_ZCJ_WarehouseID_ShAttributeID on ICWarehouseCustomProperties(WarehouseID,ShAttributeID);
go