[dbo].[StatementDocument]
CREATE TABLE [dbo].[StatementDocument]
(
[SDPriKey] [int] NOT NULL IDENTITY(1, 1),
[DocumentNumber] [varchar] (23) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Balance] [money] NULL CONSTRAINT [DF_StatementDocument_Balance] DEFAULT (0),
[DocumentDate] [datetime] NULL,
[JournalDate] [datetime] NULL,
[PostedDate] [datetime] NULL,
[ItemCode] [int] NULL,
[CustNumber] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ANPriKey] [int] NULL,
[ApplyAmount] [money] NULL CONSTRAINT [DF_StatementDocument_ApplyAmount] DEFAULT (0),
[Adjustment] [smallint] NULL CONSTRAINT [DF_StatementDocument_Adjustment] DEFAULT (0),
[BillingMinorPriKey] [int] NULL,
[OrdPriKey] [int] NULL,
[InvoiceNumber] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ServiceCodePriKey] [int] NULL,
[StDetailPriKey] [int] NULL,
[StDetailDistPriKey] [int] NULL,
[ApplyCheck] [int] NULL CONSTRAINT [DF_StatementDocument_ApplyCheck] DEFAULT (0),
[BMinDistPriKey] [int] NULL,
[ATPriKey] [int] NULL,
[GPSource] [smallint] NULL,
[OriginalAmount] [money] NULL CONSTRAINT [DF_StatementDocument_OriginalAmount] DEFAULT (0),
[DistributionAdjustmentAmount] [money] NULL CONSTRAINT [DF_StatementDocument_DistributionAdjustmentAmount] DEFAULT (0),
[AdjustAmount] [money] NULL CONSTRAINT [DF_StatementDocument_AdjustAmount] DEFAULT (0),
[InvoiceDate] [datetime] NULL,
[CustomerName] [varchar] (65) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BranchFID] [int] NULL,
[OtherApplyAmount] [money] NULL CONSTRAINT [DF_StatementDocument_OtherApplyAmount] DEFAULT ((0))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[StatementDocument] ADD CONSTRAINT [PK_StatementDocument] PRIMARY KEY CLUSTERED ([SDPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDocument_ANPriKey] ON [dbo].[StatementDocument] ([ANPriKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDocument_BillingMinorPriKey] ON [dbo].[StatementDocument] ([BillingMinorPriKey]) WITH (FILLFACTOR=70) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDocument_BMinDistPriKey] ON [dbo].[StatementDocument] ([BMinDistPriKey]) WITH (FILLFACTOR=70) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDocument_BranchFID] ON [dbo].[StatementDocument] ([BranchFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDocument_Order_DocNo] ON [dbo].[StatementDocument] ([OrdPriKey], [DocumentNumber]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDocument_ServiceCodePriKey] ON [dbo].[StatementDocument] ([ServiceCodePriKey]) WITH (FILLFACTOR=70) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDocument_1] ON [dbo].[StatementDocument] ([StDetailDistPriKey]) WITH (FILLFACTOR=70) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDocument] ON [dbo].[StatementDocument] ([StDetailPriKey]) WITH (FILLFACTOR=70) ON [PRIMARY]
GO
ALTER TABLE [dbo].[StatementDocument] ADD CONSTRAINT [FK_StatementDocument_AccountingNote] FOREIGN KEY ([ANPriKey]) REFERENCES [dbo].[AccountingNote] ([ANPriKey])
GO
ALTER TABLE [dbo].[StatementDocument] ADD CONSTRAINT [FK_StatementDocument_AcctTransactions] FOREIGN KEY ([ATPriKey]) REFERENCES [dbo].[AcctTransactions] ([ATPriKey])
GO
ALTER TABLE [dbo].[StatementDocument] ADD CONSTRAINT [FK_StatementDocument_BillingMinorItem] FOREIGN KEY ([BillingMinorPriKey]) REFERENCES [dbo].[BillingMinorItem] ([BMinPriKey])
GO
ALTER TABLE [dbo].[StatementDocument] ADD CONSTRAINT [FK_StatementDocument_BillingMinorDist] FOREIGN KEY ([BMinDistPriKey]) REFERENCES [dbo].[BillingMinorDist] ([BMinDistPriKey])
GO
ALTER TABLE [dbo].[StatementDocument] ADD CONSTRAINT [FK_StatementDocument_Branch] FOREIGN KEY ([BranchFID]) REFERENCES [dbo].[Branch] ([BranchPriKey])
GO
ALTER TABLE [dbo].[StatementDocument] ADD CONSTRAINT [FK_StatementDocument_OrderID] FOREIGN KEY ([OrdPriKey]) REFERENCES [dbo].[Orders] ([PriKey])
GO
ALTER TABLE [dbo].[StatementDocument] ADD CONSTRAINT [FK_StatementDocument_StatementDetailDist] FOREIGN KEY ([StDetailDistPriKey]) REFERENCES [dbo].[StatementDetailDist] ([SDDPriKey])
GO
ALTER TABLE [dbo].[StatementDocument] ADD CONSTRAINT [FK_StatementDocument_StatementDetail] FOREIGN KEY ([StDetailPriKey]) REFERENCES [dbo].[StatementDetail] ([SDPriKey])
GO
GRANT SELECT ON [dbo].[StatementDocument] TO [MssExec]
GRANT INSERT ON [dbo].[StatementDocument] TO [MssExec]
GRANT DELETE ON [dbo].[StatementDocument] TO [MssExec]
GRANT UPDATE ON [dbo].[StatementDocument] TO [MssExec]
GO