USE [censusweb_mdb]
GO
IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=13)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 13, 1, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=30)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 30, 1, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=49)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 49, 1, 2)

GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=575)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 575, 2, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=798)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 798, 2, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=907)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 907, 2, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=100)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 100, 3, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=576)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 576, 3, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=799)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 799, 3, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=577)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 577, 4, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=826)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 826, 4, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=578)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 578, 5, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=800)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 800, 5, 2)
GO


IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=43)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 43, 6, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=21)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 21, 4, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=64)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 64, 6, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=65)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 65, 7, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=67)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 67, 3, 2)
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=569)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 569, 7, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=20)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 20, 8, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=45)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 45, 8, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=573)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 573, 9, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=627)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 627, 9, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=574)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 574, 10, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=579)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 579, 11, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=580)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 580, 12, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=353)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 353, 0, 2)
	
GO

IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=86 AND nFieldID=354)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (86, NULL, 354, 0, 2)


GO

/*** Delete for Check in out view ***/
DELETE [dbo].[tblView] WHERE [nViewID]=72



IF NOT EXISTS(SELECT * FROM [tblView] WHERE nViewID=72)
BEGIN
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 2, 1, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 11, 1, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 65, 1, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1004, 1, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1204, 1, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 9, 2, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1099, 2, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1203, 2, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 7, 3, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 76, 3, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1082, 3, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 8, 4, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 30, 4, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 882, 4, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 71, 5, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1115, 5, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 70, 6, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 11205, 6, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 72, 7, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 74, 8, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 73, 9, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 75, 10, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1093, 11, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 918, 12, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 919, 13, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 921, 14, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 865, 15, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1078, 16, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1196, 17, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1120, 18, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 801, 19, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 21, 20, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 20, 21, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 886, 22, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 806, 23, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1023, 24, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 907, 25, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1092, 26, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1121, 27, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 993, 28, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1199, 29, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1201, 30, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1207, 31, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1202, 32, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 894, 33, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 600, 34, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 1, 35, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 353, 0, 2)
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (72, NULL, 354, 0, 2)
END

DELETE FROM [dbo].[tblView] 
WHERE [nViewID] IN (78,82, 84, 44)
AND [nFieldID]=1087

GO

DELETE FROM [dbo].[tblFieldAttribute]
WHERE [nViewID] IN (78,82, 84, 44)
AND [nFieldID]=1087

GO


/*** Do not have the Related HelpDesk issues Field in the Resources_Allocation view ***/
DELETE FROM tblView
	WHERE nViewID=74 AND nFieldID=1113
GO

/*** ASSETS LIBRARY ***/
IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=44 AND [nFieldID]=76 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (44, NULL, 76, 0, 2)
GO


/*** USERS CONTACTS MANAGE ***/
IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=18 AND [nFieldID]=21 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (18, NULL, 21, 0, 2)
GO

IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=18 AND [nFieldID]=67 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (18, NULL, 67, 0, 2)
GO

IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=18 AND [nFieldID]=68 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (18, NULL, 68, 0, 2)
GO

IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=18 AND [nFieldID]=69 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (18, NULL, 69, 0, 2)
GO

IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=18 AND [nFieldID]=70 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (18, NULL, 70, 0, 2)
GO

IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=18 AND [nFieldID]=71 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (18, NULL, 71, 0, 2)
GO

IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=18 AND [nFieldID]=72 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (18, NULL, 72, 0, 2)
GO

/*** HelpDesk ***/

/*** Add Communication_Received ***/
IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=5 AND [nFieldID]=100 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (5, NULL, 100, 7, 2);
GO








