USE [censusweb_mdb]
GO

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

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

IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=10 AND [nFieldID]=21 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (10, NULL, 21, 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


/*** Add Tasks to HELPDESK VIEW ***/
IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=5 AND [nFieldID]=781 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (5, NULL, 781, 4, 2);

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

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

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

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

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

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

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

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

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

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

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

	
/*** Add Repairs to HELPDESK VIEW ***/
IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=5 AND [nFieldID]=556 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) VALUES (5, NULL, 556, 1, 2);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/*** ASSET TYPES MANAGE ***/
-- Total Assets
IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=20 AND [nFieldID]=883 )
BEGIN
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) 
	VALUES (20, NULL, 883, 2, 2);
END

-- Total Allocated
IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=20 AND [nFieldID]=100 )
BEGIN
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) 
	VALUES (20, NULL, 100, 3, 2);
END

-- Total Available
IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=20 AND [nFieldID]=885 )
BEGIN
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) 
	VALUES (20, NULL, 885, 4, 2);
END

-- Minimum Quantity
IF NOT EXISTS( SELECT * FROM [dbo].[tblView] WHERE [nViewID]=20 AND [nFieldID]=999 )
	INSERT [dbo].[tblView] ([nViewID], [nTabID], [nFieldID], [nFieldIndex], [nStatus]) 
	VALUES (20, NULL, 999, 5, 2);
ELSE
	UPDATE [dbo].[tblView] 
	SET [nFieldIndex]=5
	WHERE [nViewID]=20 AND [nFieldID]=999 ;


GO

