USE [Configuration01_Dat]
GO
/****** Object:  Table [dbo].[tblImp_MappingField]    Script Date: 3/29/2019 9:24:08 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES  WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'tblImp_MappingField'))
BEGIN
	CREATE TABLE [dbo].[tblImp_MappingField](
		[nID] [int] NULL,
		[tInternalFieldName] [nvarchar](255) NULL,
		[tInternalTableName] [nvarchar](255) NULL,
		[nInternalDSID] [int] NULL,
		[tExternalFieldName] [nvarchar](255) NULL,
		[nValueTableID] [int] NULL,
		[tExternalFieldFormat] [nvarchar](255) NULL,
		[bForeignKey] [bit] NOT NULL,
		[bSyncOnlyNewRecord] [bit] NOT NULL,
		[nCVLookupMode] [int] NULL,
		[nFieldID] [int] NULL
	) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM [tblImp_MappingField] WHERE nID=5 AND tInternalFieldName='First_Name')
	INSERT [dbo].[tblImp_MappingField] ([nID], [tInternalFieldName], [tInternalTableName], [nInternalDSID], [tExternalFieldName], [nValueTableID], [tExternalFieldFormat], [bForeignKey], [bSyncOnlyNewRecord], [nCVLookupMode], [nFieldID]) 
	VALUES (5, N'First_Name', N'tblUser', 16, N'GivenName', 0, NULL, 0, 0, 0, 50)
GO

IF NOT EXISTS (SELECT * FROM [tblImp_MappingField] WHERE nID=5 AND tInternalFieldName='tEmailName')
	INSERT [dbo].[tblImp_MappingField] ([nID], [tInternalFieldName], [tInternalTableName], [nInternalDSID], [tExternalFieldName], [nValueTableID], [tExternalFieldFormat], [bForeignKey], [bSyncOnlyNewRecord], [nCVLookupMode], [nFieldID]) 
	VALUES (5, N'tEmailName', N'tblUser', 16, N'Mail', 0, NULL, 0, 0, 0, 58)
GO

IF NOT EXISTS (SELECT * FROM [tblImp_MappingField] WHERE nID=5 AND tInternalFieldName='tName')
	INSERT [dbo].[tblImp_MappingField] ([nID], [tInternalFieldName], [tInternalTableName], [nInternalDSID], [tExternalFieldName], [nValueTableID], [tExternalFieldFormat], [bForeignKey], [bSyncOnlyNewRecord], [nCVLookupMode], [nFieldID]) 
	VALUES (5, N'tName', N'tblUser', 16, N'DisplayName', 0, NULL, 0, 0, 0, 4)
GO

IF NOT EXISTS (SELECT * FROM [tblImp_MappingField] WHERE nID=5 AND tInternalFieldName='tUID')
	INSERT [dbo].[tblImp_MappingField] ([nID], [tInternalFieldName], [tInternalTableName], [nInternalDSID], [tExternalFieldName], [nValueTableID], [tExternalFieldFormat], [bForeignKey], [bSyncOnlyNewRecord], [nCVLookupMode], [nFieldID]) 
	VALUES (5, N'tUID', N'tblUser', 16, N'Id', 0, NULL, 1, 0, 0, 106)
GO

IF NOT EXISTS (SELECT * FROM [tblImp_MappingField] WHERE nID=5 AND tInternalFieldName='tUserName')
	INSERT [dbo].[tblImp_MappingField] ([nID], [tInternalFieldName], [tInternalTableName], [nInternalDSID], [tExternalFieldName], [nValueTableID], [tExternalFieldFormat], [bForeignKey], [bSyncOnlyNewRecord], [nCVLookupMode], [nFieldID]) 
	VALUES (5, N'tUserName', N'tblUser', 16, N'UserPrincipalName', 0, NULL, 0, 0, 0, 48)
GO

IF NOT EXISTS (SELECT * FROM [tblImp_MappingField] WHERE nID=5 AND tInternalFieldName='Phone_3')
	INSERT [dbo].[tblImp_MappingField] ([nID], [tInternalFieldName], [tInternalTableName], [nInternalDSID], [tExternalFieldName], [nValueTableID], [tExternalFieldFormat], [bForeignKey], [bSyncOnlyNewRecord], [nCVLookupMode], [nFieldID]) 
	VALUES (5, N'Phone_3', N'tblUser', 16, N'MobilePhone', 0, NULL, 0, 0, 0, 141)
GO

IF NOT EXISTS (SELECT * FROM [tblImp_MappingField] WHERE nID=5 AND tInternalFieldName='Last_Name')
	INSERT [dbo].[tblImp_MappingField] ([nID], [tInternalFieldName], [tInternalTableName], [nInternalDSID], [tExternalFieldName], [nValueTableID], [tExternalFieldFormat], [bForeignKey], [bSyncOnlyNewRecord], [nCVLookupMode], [nFieldID]) 
	VALUES (5, N'Last_Name', N'tblUser', 16, N'Surname', 0, NULL, 0, 0, 0, 51)
GO
