IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CARD_NOTE]') AND name = N'IX_T_CARD_NOTE_Filtered_1')
DROP INDEX [IX_T_CARD_NOTE_Filtered_1] ON [AKUZ].[T_CARD_NOTE]
GO
CREATE INDEX [IX_T_CARD_NOTE_Filtered_1] ON [AKUZ].[T_CARD_NOTE] ( EmdrDocType ) WHERE ([ReadyToBeSent]= 1 AND [IsDelayed]= 0)
GO

IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_EMDR_DOC_TYPE]') AND name = N'IX_T_EMDR_DOC_TYPE_WhereToSend')
DROP INDEX [IX_T_EMDR_DOC_TYPE_WhereToSend] ON [AKUZ].[T_EMDR_DOC_TYPE]
GO
CREATE INDEX [IX_T_EMDR_DOC_TYPE_WhereToSend] ON AKUZ.T_EMDR_DOC_TYPE (SendingPrioritet)
GO

IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_EMDR_MESSAGE]') AND name = N'IX_T_EMDR_MESSAGE_Filtered_1')
DROP INDEX [IX_T_EMDR_MESSAGE_Filtered_1] ON [AKUZ].[T_EMDR_MESSAGE]
GO
CREATE INDEX [IX_T_EMDR_MESSAGE_Filtered_1] ON [AKUZ].[T_EMDR_MESSAGE] (WhereToSend, RegistrationState ) INCLUDE ( [CardNote]) WHERE (RegistrationState = 0)
GO