USE [censusweb_mdb]
GO

UPDATE tblView SET nFieldIndex=29 WHERE nViewID=10 AND nFieldID=137 AND nFieldIndex=0
UPDATE tblView SET nFieldIndex=30 WHERE nViewID=10 AND nFieldID=287 AND nFieldIndex=0
GO

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

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


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

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

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


UPDATE tblView SET nFieldIndex=18 WHERE nViewID=47 AND nFieldID=945 AND nFieldIndex=16
UPDATE tblView SET nFieldIndex=19 WHERE nViewID=47 AND nFieldID=953 AND nFieldIndex=17
UPDATE tblView SET nFieldIndex=20 WHERE nViewID=47 AND nFieldID=914 AND nFieldIndex=18
UPDATE tblView SET nFieldIndex=21 WHERE nViewID=47 AND nFieldID=907 AND nFieldIndex=19
UPDATE tblView SET nFieldIndex=22 WHERE nViewID=47 AND nFieldID=954 AND nFieldIndex=20
GO



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

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

UPDATE tblView SET nFieldIndex=18 WHERE nViewID=48 AND nFieldID=945 AND nFieldIndex=16
UPDATE tblView SET nFieldIndex=19 WHERE nViewID=48 AND nFieldID=953 AND nFieldIndex=17
UPDATE tblView SET nFieldIndex=20 WHERE nViewID=48 AND nFieldID=914 AND nFieldIndex=18
UPDATE tblView SET nFieldIndex=21 WHERE nViewID=48 AND nFieldID=954 AND nFieldIndex=19
GO

--Remove the Container field from the Allocation view
DELETE FROM tblView WHERE nViewID=74 AND nFieldID=1095
GO

--move the key field down
UPDATE tblView SET nFieldIndex=4 WHERE nViewID=74 AND nFieldID=1096 AND nFieldIndex=3
GO

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



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

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

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

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

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

--Don't export the Actions tab in asset views--
DELETE FROM tblView 
  WHERE nFieldID=805 AND nViewID IN(
	SELECT nViewID FROM tblWebViews WHERE nProjectID=15 AND nViewID NOT IN(20,24,83))
GO







