		
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON
GO
SET DATEFORMAT YMD
GO

INSERT INTO [dbo].[REF_CUSTOM_CONTROL] ([TableName], [FieldName], [CustomisationID], [Caption], [TabOrder], [ListOrder], [Enabled], [ControlTop], [ControlLeft], [ControlWidth], [ControlHeight], [Mask], [DefaultValue], [ControlType], [Compulsory], [LookupID], [ToolTipText], [ControlBackColor], [FontColor], [FontStyle], [FontBold], [FontItalic], [FontUnderline], [FontSize], [Visible], [MaximumLength], [CharacterTable], [Characters], [ShowCodesInCombo], [Justification], [MinValue], [MaxValue], [IntDigits], [DecDigits], [ValidateMask], [ShowZero], [fmtThousands], [EntityUnique], [TreatZeroAsBlank], [ObjectChooserTable], [OverideComboTextField], [MiscSelectorTable], [WidthOffset], [DisplayInHeader], [KeyField], [LabelAbove], [HideLabelOnFrame], [ImageMode], [ImageFilePattern], [ScaleImage], [MaintainAspect], [MiscSelectorSortFields], [MailMergeReport], [NULLDisplayField], [DisplayTab], [SecurityIdentifier], [ExcelTextOutput], [Hidden], [Locked], [DataProtectionTrigger]) VALUES (N'DT_EMPLOYEE', N'MANAGERREF', 0, N'Managerref', 0, 0, 0, 0, 0, 4, 1, N'', NULL, 0, 0, NULL, N'Managerref', -2147483633, -2147483630, N'Calibri', 0, 0, 0, 9, 1, 0, N'', -1, 0, 0, NULL, NULL, NULL, NULL, 0, 1, N',', 0, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, N'', 0, 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0)
INSERT INTO [dbo].[REF_SQLFIELDS] ([CustomisationID], [Table_Name], [Field_Name], [Version], [Code], [OnByDefault], [InLine]) VALUES (0, N'DT_EMPLOYEE', N'ManagerRef', 1, N'SELECT TOP 1 CAST(DTEMAN.EmployeeId as nvarchar(128))
FROM DT_EMPLOYEE DTEMAN
INNER JOIN LNK_EMPLOYEE_CONTRACT LEC
ON LEC.Left_Join = DTEMAN.Entity_Id
AND [CalcDate] BETWEEN LEC.Start_Date AND COALESCE(LEC.End_Date, [CalcDate])
AND [CalcDate] BETWEEN DTEMAN.Entity_Start_Date AND COALESCE(DTEMAN.Entity_End_Date, [CalcDate])
INNER JOIN LNK_JOB_CONTRACT_VIRTUAL LJC
ON LJC.Right_Join = LEC.Right_Join
AND LJC.Left_Join = Manager_Man.ManagingJob 
AND [CalcDate] BETWEEN LJC.Start_Date AND COALESCE(LJC.End_Date, [CalcDate])
ORDER BY LJC.Start_Date DESC{{J}}[#J#Manager]', 0, 1)
