CREATE TABLE [dbo].[SysFile]
(
[PriKey] [int] NOT NULL IDENTITY(1, 1),
[ServiceStartTime] [datetime] NOT NULL,
[UserDefinedLabel1] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserDefinedLabel2] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserDefinedLabel3] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserDefinedLabel4] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserDefinedLabel5] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserDefinedLabel6] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserDefinedLabel7] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserDefinedLabel8] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserDefinedActive1] [int] NULL,
[UserDefinedActive2] [int] NULL,
[UserDefinedActive3] [int] NULL,
[UserDefinedActive4] [int] NULL,
[UserDefinedActive5] [int] NULL,
[UserDefinedActive6] [int] NULL,
[UserDefinedActive7] [int] NULL,
[UserDefinedActive8] [int] NULL,
[OutlookCalendar] [int] NULL,
[VLAutoDispatch] [bit] NULL,
[DriverDivisionOptionFlag] [bit] NULL,
[InvoiceManualAddressFlag] [bit] NULL,
[Key1] [varchar] (512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Key2] [varchar] (512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CountryCodeStandardFID] [int] NULL,
[PaymentCodeFID] [int] NULL,
[UseDefaultEmail] [bit] NOT NULL CONSTRAINT [DF_SysFile_UseDefaultEmail] DEFAULT ((0)),
[OutlookEmail] [bit] NOT NULL CONSTRAINT [DF_SysFile_OutlookEmail] DEFAULT ((0)),
[CustomTitle] [nvarchar] (120) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[WorkWeekStart] [int] NOT NULL,
[DefaultLaborRatingGroup] [int] NULL,
[EnableDuplicateOrder] [bit] NOT NULL CONSTRAINT [DF_SysFile_EnableDuplicateOrder] DEFAULT ((1)),
[Key3] [varchar] (512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IncludeSpecialInstructionsOnWorkTicket] [bit] NOT NULL CONSTRAINT [DF_SysFile_IncludeSpecialInstructionsOnWorkTicket] DEFAULT ((1)),
[MssTimeZoneFID] [int] NULL,
[OnlyCommissionLSCrewOnWorkTicket] [bit] NOT NULL CONSTRAINT [DF_SysFile_OnlyCommissionLSCrewOnWorkTicket] DEFAULT ((0)),
[RestrictSalespersonOrderVisibility] [bit] NOT NULL CONSTRAINT [DF_RestrictSalespersonOrderVisibility] DEFAULT ((0)),
[HideCommissionsFromNonRevenueEntryManagers] [bit] NOT NULL CONSTRAINT [DF_HideCommissionsFromNonRevenueEntryManagers] DEFAULT ((0)),
[AutoPlaceSalesCommissionsOnHold] [bit] NOT NULL CONSTRAINT [DF_AutoPlaceSalesCommissionsOnHold] DEFAULT ((0)),
[MoversConnectTraceId] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SysFile_MoversConnectTraceId] DEFAULT (substring(CONVERT([varchar](40),newid()),(1),(8)))
) ON [PRIMARY]
GO
create trigger [dbo].[SysFileUdfActiveChanged] on [dbo].[SysFile]
after update
as
set nocount on
declare @theUserDefinedLabel varchar(20) = 'User Defined Label '
declare @theInactiveField varchar(20) = ' *Inactive Field*'
if( update( UserDefinedActive1 ) )
begin
update SUDFNumber set
[Description] = @theUserDefinedLabel + ltrim( str( SUDFNumber.SUDFNumberID ) ) + case when inserted.UserDefinedActive1 = 0 then @theInactiveField else '' end
from inserted
inner join SUDFNumber on SUDFNumber.SUDFNumberID = 1
end
if( update( UserDefinedActive2 ) )
begin
update SUDFNumber set
[Description] = @theUserDefinedLabel + ltrim( str( SUDFNumber.SUDFNumberID ) ) + case when inserted.UserDefinedActive2 = 0 then @theInactiveField else '' end
from inserted
inner join SUDFNumber on SUDFNumber.SUDFNumberID = 2
end
if( update( UserDefinedActive3 ) )
begin
update SUDFNumber set
[Description] = @theUserDefinedLabel + ltrim( str( SUDFNumber.SUDFNumberID ) ) + case when inserted.UserDefinedActive3 = 0 then @theInactiveField else '' end
from inserted
inner join SUDFNumber on SUDFNumber.SUDFNumberID = 3
end
if( update( UserDefinedActive4 ) )
begin
update SUDFNumber set
[Description] = @theUserDefinedLabel + ltrim( str( SUDFNumber.SUDFNumberID ) ) + case when inserted.UserDefinedActive4 = 0 then @theInactiveField else '' end
from inserted
inner join SUDFNumber on SUDFNumber.SUDFNumberID = 4
end
if( update( UserDefinedActive5 ) )
begin
update SUDFNumber set
[Description] = @theUserDefinedLabel + ltrim( str( SUDFNumber.SUDFNumberID ) ) + case when inserted.UserDefinedActive5 = 0 then @theInactiveField else '' end
from inserted
inner join SUDFNumber on SUDFNumber.SUDFNumberID = 5
end
if( update( UserDefinedActive6 ) )
begin
update SUDFNumber set
[Description] = @theUserDefinedLabel + ltrim( str( SUDFNumber.SUDFNumberID ) ) + case when inserted.UserDefinedActive6 = 0 then @theInactiveField else '' end
from inserted
inner join SUDFNumber on SUDFNumber.SUDFNumberID = 6
end
if( update( UserDefinedActive7 ) )
begin
update SUDFNumber set
[Description] = @theUserDefinedLabel + ltrim( str( SUDFNumber.SUDFNumberID ) ) + case when inserted.UserDefinedActive7 = 0 then @theInactiveField else '' end
from inserted
inner join SUDFNumber on SUDFNumber.SUDFNumberID = 7
end
if( update( UserDefinedActive8 ) )
begin
update SUDFNumber set
[Description] = @theUserDefinedLabel + ltrim( str( SUDFNumber.SUDFNumberID ) ) + case when inserted.UserDefinedActive8 = 0 then @theInactiveField else '' end
from inserted
inner join SUDFNumber on SUDFNumber.SUDFNumberID = 8
end
GO
ALTER TABLE [dbo].[SysFile] ADD CONSTRAINT [PK_SysFile] PRIMARY KEY CLUSTERED ([PriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[SysFile] ADD CONSTRAINT [FK_SysFile_CountryCodeStandard] FOREIGN KEY ([CountryCodeStandardFID]) REFERENCES [dbo].[CountryCodeStandard] ([CountryCodeStandardID])
GO
ALTER TABLE [dbo].[SysFile] ADD CONSTRAINT [FK_SysFile_LaborRatingGroup] FOREIGN KEY ([DefaultLaborRatingGroup]) REFERENCES [dbo].[LaborRatingGroup] ([LaborRatingGroupID])
GO
ALTER TABLE [dbo].[SysFile] ADD CONSTRAINT [FK_Sysfile_MssTimeZone] FOREIGN KEY ([MssTimeZoneFID]) REFERENCES [dbo].[MssTimeZone] ([MssTimeZoneID])
GO
ALTER TABLE [dbo].[SysFile] ADD CONSTRAINT [FK_SysFile_PaymentCode] FOREIGN KEY ([PaymentCodeFID]) REFERENCES [dbo].[PaymentCode] ([PaymentCodePriKey])
GO
ALTER TABLE [dbo].[SysFile] ADD CONSTRAINT [FK_SysFile_DayInWeek] FOREIGN KEY ([WorkWeekStart]) REFERENCES [dbo].[DayInWeek] ([DayInWeekID])
GO
GRANT SELECT ON [dbo].[SysFile] TO [MssExec]
GRANT INSERT ON [dbo].[SysFile] TO [MssExec]
GRANT DELETE ON [dbo].[SysFile] TO [MssExec]
GRANT UPDATE ON [dbo].[SysFile] TO [MssExec]
GO