if exists
(select * from sys.indexes i where i.object_id = object_id('PHARM.T_BILL_OF_GOODS', 'U') and i.name = 'IX_T_BILL_OF_GOODS_Active') 
	DROP INDEX IX_T_BILL_OF_GOODS_Active ON PHARM.T_BILL_OF_GOODS;
GO
if exists
(select * from sys.indexes i where i.object_id = object_id('PHARM.T_BILL_OF_GOODS', 'U') and i.name = 'IX_T_BILL_OF_GOODS_CTrn') 
	DROP INDEX IX_T_BILL_OF_GOODS_CTrn ON PHARM.T_BILL_OF_GOODS;
GO
if exists(select* from sys.indexes i where i.[object_id] = object_id('PHARM.T_BILL_OF_GOODS', 'U') and i.name = 'IX_T_BILL_OF_GOODS_ExportCode')
	DROP INDEX IX_T_BILL_OF_GOODS_ExportCode ON PHARM.T_BILL_OF_GOODS;
go
if exists
(select * from sys.indexes i where i.object_id = object_id('PHARM.T_BILL_OF_GOODS', 'U') and i.name = 'IX_T_BILL_OF_GOODS_MedicationForms') 
	DROP INDEX IX_T_BILL_OF_GOODS_MedicationForms ON PHARM.T_BILL_OF_GOODS;
GO

if exists
(select * from sys.indexes i where i.object_id = object_id('PHARM.T_BILL_OF_GOODS', 'U') and i.name = 'IX_BILL_OF_GOODS_3_4_20241121') 
	DROP INDEX IX_BILL_OF_GOODS_3_4_20241121 ON PHARM.T_BILL_OF_GOODS;
GO
CREATE INDEX [IX_BILL_OF_GOODS_3_4_20241121] ON [PHARM].[T_BILL_OF_GOODS] (
	[ExportCode],
	[CTrn],
	[Active]
	)  
INCLUDE (
	[DoseView], 
	[PackQuantity], 
	[MedicationForms], 
	[EhrRus2m69i03gtd]
	) 
WITH (
	FILLFACTOR=100, 
	SORT_IN_TEMPDB=ON, 
	MAXDOP = 0);

	
if exists
(select * from sys.indexes i where i.object_id = object_id('PHARM.T_BILL_OF_GOODS', 'U') and i.name = 'IX_BILL_OF_GOODS_OtherID_20241121') 
	DROP INDEX [IX_BILL_OF_GOODS_OtherID_20241121] ON PHARM.T_BILL_OF_GOODS;
GO
CREATE INDEX [IX_BILL_OF_GOODS_OtherID_20241121] ON [PHARM].[T_BILL_OF_GOODS] ( [OtherID] ) WITH (FILLFACTOR=100, SORT_IN_TEMPDB=ON, MAXDOP = 0);