[dbo].[OfficeIndustrialOrder]
CREATE TABLE [dbo].[OfficeIndustrialOrder]
(
[OfficeIndustrialOrderID] [int] NOT NULL IDENTITY(1, 1),
[OrderFID] [int] NOT NULL,
[ProjectManager] [int] NULL,
[JobStartDate] [datetime] NULL,
[JobEndDate] [datetime] NULL,
[HeadCount] [int] NULL,
[ClientNote] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OperationalNote] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE trigger [dbo].[OfficeIndustrialOrderTaskFieldChanged] on [dbo].[OfficeIndustrialOrder]
after insert, update
as
set nocount on
if( update( JobStartDate ) or update( JobEndDate ) )
begin
update ToDo set ToDo.DueDate =
case DependencyDate.FieldName
when 'JobStartDate' then dbo.udfTaskDueDate( ToDo.DueType, ToDo.DueDays, inserted.JobStartDate )
when 'JobEndDate' then dbo.udfTaskDueDate( ToDo.DueType, ToDo.DueDays, inserted.JobEndDate )
else ToDo.DueDate
end
from ToDo
inner join inserted on inserted.OrderFID = ToDo.OrderID
inner join DependencyDate on ToDo.DependencyDateID = DependencyDate.DependencyDateID
where DependencyDate.TableName = 'OfficeIndustrialOrder'
end
if( update( ProjectManager ) )
begin
update ToDo set TaskUserFID =
case CoordinatorType.FieldName
when 'ProjectManager' then inserted.ProjectManager
end
from ToDo
inner join inserted on inserted.OrderFID = ToDo.OrderID
inner join CoordinatorType on ToDo.CoordinatorTypeFID = CoordinatorType.CoordinatorTypeID
where CoordinatorType.TableName = 'OfficeIndustrialOrder'
end
GO
ALTER TABLE [dbo].[OfficeIndustrialOrder] ADD CONSTRAINT [PK_OfficeIndustrialOrder] PRIMARY KEY NONCLUSTERED ([OfficeIndustrialOrderID]) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_OfficeIndustrialOrder_OrderFID] ON [dbo].[OfficeIndustrialOrder] ([OrderFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OfficeIndustrialOrder] ADD CONSTRAINT [FK_OfficeIndustrialOrder_Orders] FOREIGN KEY ([OrderFID]) REFERENCES [dbo].[Orders] ([PriKey])
GO
ALTER TABLE [dbo].[OfficeIndustrialOrder] ADD CONSTRAINT [FK_OfficeIndustrialOrder_Sysuser] FOREIGN KEY ([ProjectManager]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
GRANT SELECT ON [dbo].[OfficeIndustrialOrder] TO [MssExec]
GRANT INSERT ON [dbo].[OfficeIndustrialOrder] TO [MssExec]
GRANT DELETE ON [dbo].[OfficeIndustrialOrder] TO [MssExec]
GRANT UPDATE ON [dbo].[OfficeIndustrialOrder] TO [MssExec]
GO