[dbo].[InternationalBookingNumberDate]
CREATE TABLE [dbo].[InternationalBookingNumberDate]
(
[InternationalBookingNumberDateID] [int] NOT NULL IDENTITY(1, 1),
[OrdersFID] [int] NOT NULL,
[PickupEstimatedDate] [datetime] NULL,
[PickupActualDate] [datetime] NULL,
[ReturnEstimatedDate] [datetime] NULL,
[ReturnActualDate] [datetime] NULL
) ON [PRIMARY]
GO
create trigger [dbo].[InternationalBookingNumberDateTaskFieldChanged] on [dbo].[InternationalBookingNumberDate]
after insert, update
as
set nocount on
if( update( PickupEstimatedDate ) or update( PickupActualDate ) or
update( ReturnEstimatedDate ) or update( ReturnActualDate )
)
begin
update ToDo set
ToDo.DueDate = dbo.udfTaskDueDate( ToDo.duetype, ToDo.duedays, dbo.GetInternationalBookingNumberDateByOrderAndType( ToDo.OrderID, DependencyDate.FieldName ) )
from ToDo
inner join inserted on inserted.OrdersFID = ToDo.OrderID
inner join DependencyDate on ToDo.DependencyDateID = DependencyDate.DependencyDateID
where DependencyDate.TableName = 'InternationalBookingNumberDate'
end
GO
ALTER TABLE [dbo].[InternationalBookingNumberDate] ADD CONSTRAINT [PK_InternationalBookingNumberDate] PRIMARY KEY NONCLUSTERED ([InternationalBookingNumberDateID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[InternationalBookingNumberDate] ADD CONSTRAINT [IX_InternationalBookingNumberDate_OrdersFID] UNIQUE CLUSTERED ([OrdersFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[InternationalBookingNumberDate] ADD CONSTRAINT [FK_InternationalBookingNumberDate_Orders] FOREIGN KEY ([OrdersFID]) REFERENCES [dbo].[Orders] ([PriKey])
GO
GRANT SELECT ON [dbo].[InternationalBookingNumberDate] TO [MssExec]
GRANT INSERT ON [dbo].[InternationalBookingNumberDate] TO [MssExec]
GRANT DELETE ON [dbo].[InternationalBookingNumberDate] TO [MssExec]
GRANT UPDATE ON [dbo].[InternationalBookingNumberDate] TO [MssExec]
GO