Use CTCBIMData;
-- Updates the schema of CTCBIMData from any version to the latest version.
GO


-- ***********************************************************
-- ***********************************************************
--
-- This script needs to be run on SQL server if you are  
-- upgrading to a new version of BIM Data Suite.
-- 
-- It DOES NOT need to be run on SQL server if you are 
-- installing BIM Data Suite for the first time.
-- 
-- ***********************************************************
-- ***********************************************************
 BEGIN TRY;

    BEGIN TRANSACTION;

	-- Must remove the old diagram before making schema changes
	exec sp_dropdiagram 'Diagram_All'
	
	---------------------------------------------------------------------------------------------------------------------------------------------
	-- GET THE CURRENT SCHEMA VERSION FROM THE SCHEMADATA TABLE
	---------------------------------------------------------------------------------------------------------------------------------------------

	DECLARE @palvers as int = -1;
	DECLARE @snapvers as int = -1;
	DECLARE @Name NVARCHAR(100), @Sql NVARCHAR(255);

	-- First look for the table in the most recent schema namespace name
	IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = N'asset' AND TABLE_NAME = N'SchemaData')
	BEGIN
		SET @palvers = (SELECT [CurrentActivitySchemaVersion] FROM  [asset].SchemaData);
		SET @snapvers = (SELECT [CurrentSnapshotSchemaVersion] FROM [asset].SchemaData);
	END
	ELSE
		BEGIN
			-- Check for the schema versions in the older schema namespace if we need to
			IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = N'dbo' AND TABLE_NAME = N'SchemaData')
			BEGIN
			   SET @palvers = (SELECT [CurrentActivitySchemaVersion] FROM  [dbo].SchemaData);
			   SET @snapvers = (SELECT [CurrentSnapshotSchemaVersion] FROM [dbo].SchemaData);
			END

		END

	PRINT 'Original PAL schema version = ' + CAST(@palvers as VARCHAR)
	PRINT 'Original Snapshot schema version = ' + CAST(@snapvers as VARCHAR)

	IF @snapvers = 1 
		BEGIN
			---------------------------------------------------------------------------------------------------------------------------------------------
			-- MAKE CHANGES FROM SNAPSHOT SCHEMA VERSION 1
			---------------------------------------------------------------------------------------------------------------------------------------------

			PRINT ''
			PRINT 'Updating snapshot schema from version 1 to version 3'

			-- Snapshot tables modifications
			PRINT 'Snapshot - Updating ElementDefinition table structure'
			Alter Table ElementDefinition ALTER COLUMN [Name] [NVARCHAR](MAX) NOT NULL
			PRINT 'Snapshot - Updating ElementType table structure'
			Alter Table ElementType ALTER COLUMN [Name] [NVARCHAR](MAX) NOT NULL
			PRINT 'Snapshot - Updating ElementInstance table structure'
			Alter Table ElementInstance ALTER COLUMN [ElementDefinitionName] [NVARCHAR](MAX) NOT NULL
			Alter Table ElementInstance ALTER COLUMN [ElementTypeName] [NVARCHAR](MAX) NOT NULL
			Alter Table ElementInstance ALTER COLUMN [OwnerViewName] [NVARCHAR](MAX)
			PRINT 'Snapshot - Updating ElementParameterValue table structure'
			Alter Table ElementParameterValue ALTER COLUMN [ElementDefinitionName] [NVARCHAR](MAX) NOT NULL
			Alter Table ElementParameterValue ALTER COLUMN [ElementTypeName] [NVARCHAR](MAX)
			PRINT 'Snapshot - Updating GroupInstance table structure'
			Alter Table GroupInstance ALTER COLUMN [OwnerViewName] [NVARCHAR](MAX)

		-- The snapshot schema is now at the next released version.	
		SET @snapvers = 3   -- There was no 2
			
		END;  -- If Snapshot schema version 1 is current

	IF @palvers = 1 
		BEGIN
			---------------------------------------------------------------------------------------------------------------------------------------------
			-- MAKE CHANGES FROM PAL SCHEMA VERSION 1
			---------------------------------------------------------------------------------------------------------------------------------------------
			SET ANSI_NULLS ON
			SET QUOTED_IDENTIFIER ON
		  
			PRINT ''
			PRINT 'Updating pal schema from version 1 to version 3'
		  
			-- PAL new tables

			-- Create table [dbo].[LogAddIns]
			IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'LogAddIns')
				BEGIN
					PRINT 'PAL - Creating table LogAddIns'
					CREATE TABLE [dbo].[LogAddIns](
						[Id] [uniqueidentifier] NOT NULL,
						[DocSessionId] [uniqueidentifier] NOT NULL,
						[Name] [nvarchar](255) NOT NULL,
						[LogDateTime] [datetime] NOT NULL
					 CONSTRAINT [PK_dbo.LogAddIns] PRIMARY KEY CLUSTERED 
					(
						[Id] ASC
					)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
					) ON [PRIMARY]


					ALTER TABLE [dbo].[LogAddIns] ADD  CONSTRAINT [DF__LogAddIns__Id]  DEFAULT (newid()) FOR [Id]

					ALTER TABLE [dbo].[LogAddIns]  WITH CHECK ADD  CONSTRAINT [FK_dbo.LogAddIns_dbo.LogDocuments_DocSessionId] FOREIGN KEY([DocSessionId])
					REFERENCES [dbo].[LogDocSessions] ([Id])
					ON UPDATE CASCADE
					ON DELETE CASCADE

					ALTER TABLE [dbo].[LogAddIns] CHECK CONSTRAINT [FK_dbo.LogAddIns_dbo.LogDocuments_DocSessionId]
				END;

			
			-- Create table [dbo].[LogCrashes]
			IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'LogCrashes')
				BEGIN

					PRINT 'PAL - Creating table LogCrashes'
			
					CREATE TABLE [dbo].[LogCrashes](
						[Id] [uniqueidentifier] NOT NULL,
						[DocSessionId] [uniqueidentifier] NOT NULL,
						[UserName] [nvarchar](100) NOT NULL,
						[CentralFileName] [nvarchar](255) NOT NULL,
						[LocalFileName] [nvarchar](255) NOT NULL,
						[RevitVersion] [nvarchar](100) NOT NULL,
						[LocalFileSize] [int] NOT NULL,
						[Description] [nvarchar](255),
						[ExceptionDateTime] [datetime] NOT NULL,
						[LogDateTime] [datetime] NOT NULL
					 CONSTRAINT [PK_dbo.LogCrashes] PRIMARY KEY CLUSTERED 
					(
						[Id] ASC
					)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
					) ON [PRIMARY]

					ALTER TABLE [dbo].[LogCrashes] ADD  CONSTRAINT [DF__LogCrashes__Id]  DEFAULT (newid()) FOR [Id]

					ALTER TABLE [dbo].[LogCrashes]  WITH CHECK ADD  CONSTRAINT [FK_dbo.LogCrashes_dbo.LogDocuments_DocSessionId] FOREIGN KEY([DocSessionId])
					REFERENCES [dbo].[LogDocSessions] ([Id])
					ON UPDATE CASCADE
					ON DELETE CASCADE

					ALTER TABLE [dbo].[LogCrashes] CHECK CONSTRAINT [FK_dbo.LogCrashes_dbo.LogDocuments_DocSessionId]

				END;

			
			-- Create table [dbo].[LogElements]
			IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'LogElements')
				BEGIN

					PRINT 'PAL - Creating table LogElements'

					CREATE TABLE [dbo].[LogElements](
						[Id] [uniqueidentifier] NOT NULL,
						[DocSessionId] [uniqueidentifier] NOT NULL,
						[ElementId] [int] NOT NULL,
						[ActionType] [int] NOT NULL,
						[LogDateTime] [datetime] NOT NULL
					 CONSTRAINT [PK_dbo.LogElements] PRIMARY KEY CLUSTERED 
					(
						[Id] ASC
					)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
					) ON [PRIMARY]

					ALTER TABLE [dbo].[LogElements] ADD  CONSTRAINT [DF__LogElements__Id]  DEFAULT (newid()) FOR [Id]

					ALTER TABLE [dbo].[LogElements]  WITH CHECK ADD  CONSTRAINT [FK_dbo.LogElements_dbo.LogDocuments_DocSessionId] FOREIGN KEY([DocSessionId])
					REFERENCES [dbo].[LogDocSessions] ([Id])
					ON UPDATE CASCADE
					ON DELETE CASCADE

					ALTER TABLE [dbo].[LogElements] CHECK CONSTRAINT [FK_dbo.LogElements_dbo.LogDocuments_DocSessionId]

				END;

			
			-- The PAL schema is now at the next released version.
			SET @palvers = 3   -- There was no version 2
			
		END;  -- If PAL schema version 1 is current 
	
	---------------------------------------------------------------------------------------------------------------------------------------------
	---------------------------------------------------------------------------------------------------------------------------------------------
	---------------------------------------------------------------------------------------------------------------------------------------------
	--
	--  UPDATE FROM SCHEMA VERSION 3 TO SCHEMA VERSION 4 BEGINS HERE
	--
	---------------------------------------------------------------------------------------------------------------------------------------------
	---------------------------------------------------------------------------------------------------------------------------------------------
	---------------------------------------------------------------------------------------------------------------------------------------------


	IF (@palvers = 3 OR @snapvers = 3)  
		---------------------------------------------------------------------------------------------------------------------------------------------
		-- MAKE INITIAL CHANGES FROM PAL OR SNAPSHOT SCHEMA VERSION 3 (to global things)
		---------------------------------------------------------------------------------------------------------------------------------------------
		BEGIN

			PRINT ''
			PRINT 'Updating global things from schema version 3 to version 4'

			-- Create the new schema names pal, asset ans snapshot

			IF (NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'pal')) 
			BEGIN
				PRINT 'Global - Creating new pal schema'
				EXEC ('CREATE SCHEMA [pal] AUTHORIZATION [dbo]')
			END

			IF (NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'asset')) 
			BEGIN
				PRINT 'Global - Creating new asset schema'
				EXEC ('CREATE SCHEMA [asset] AUTHORIZATION [dbo]')
			END

			IF (NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'snapshot')) 
			BEGIN
				PRINT 'Global - Creating new snapshot schema'
				EXEC ('CREATE SCHEMA [snapshot] AUTHORIZATION [dbo]')
			END

			

			-- CHANGE THE PROJECTS, PROJECTPATHS AND SCHEMADATA TABLES TO USE THE NEW ASSET SCHEMA 

			DECLARE Table_Cursor CURSOR FOR  
			SELECT TABLE_SCHEMA + '.' + TABLE_NAME  AS t
			FROM INFORMATION_SCHEMA.TABLES 
			WHERE TABLE_SCHEMA = 'dbo'
			AND (TABLE_NAME = 'Projects'
			OR TABLE_NAME = 'ProjectPaths'
			OR TABLE_NAME = 'SchemaData'
			);

			OPEN Table_Cursor;  
			FETCH NEXT FROM Table_Cursor INTO @Name;  
			WHILE @@FETCH_STATUS = 0
			   BEGIN  
				  SET @Sql = 'ALTER SCHEMA asset TRANSFER ' + @Name + ';'
				  print 'Global - Transferring table ' + @Name + ' to schema: asset';
				  exec (@Sql);
				  FETCH NEXT FROM Table_Cursor INTO @Name; 
			   END;  
			CLOSE Table_Cursor;  
			DEALLOCATE Table_Cursor;  

			
			PRINT ''
			PRINT 'Start pluralization removal of general tables'
			PRINT 'Renaming Table Projects to Project'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'Projects' )
				BEGIN
					 EXEC ('sp_rename ''asset.Projects'', ''Project''');
			END

			PRINT 'Renaming Table ProjectPaths to ProjectPath'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ProjectPaths' )
			BEGIN
					EXEC ('sp_rename ''asset.ProjectPaths'', ''ProjectPath''');
			END	
			

			-- MAKE FIELD CHANGES TO ASSET TABLES TO MATCH THE SAME CORE DATABASE TABLES, 
			-- EXCEPT FOR CHANGING GUID TO INT PK FIELDS AND RELINKING TABLES, WHICH WILL COME LATER.

			PRINT 'ALTER TABLE asset.Project ADD CompanyID INT NOT NULL DEFAULT(1)'
			ALTER TABLE asset.Project ADD CompanyID INT NOT NULL DEFAULT(1)
			
			PRINT 'ALTER TABLE asset.Project ADD AddedByUserID INT NULL'
			ALTER TABLE asset.Project ADD AddedByUserID INT NULL 
			
			PRINT 'ALTER TABLE asset.Project ADD UpdatedByUserID INT NULL'
			ALTER TABLE asset.Project ADD UpdatedByUserID INT NULL 
			
			PRINT 'ALTER TABLE asset.Project ADD Status INT NOT NULL DEFAULT(0)'
			ALTER TABLE asset.Project ADD Status INT NOT NULL DEFAULT(0)
			
			PRINT 'ALTER TABLE asset.Project DROP CONSTRAINT [DF__Projects__Update__619B8048]'
			ALTER TABLE asset.Project DROP CONSTRAINT [DF__Projects__Update__619B8048]
			
			PRINT 'ALTER TABLE asset.Project DROP COLUMN UpdatedBy'
			ALTER TABLE asset.Project DROP COLUMN UpdatedBy
			
			PRINT 'ALTER TABLE asset.Project DROP CONSTRAINT [DF__Projects__Create__628FA481]'
			ALTER TABLE asset.Project DROP CONSTRAINT [DF__Projects__Create__628FA481]
			
			PRINT 'ALTER TABLE asset.Project DROP COLUMN CreatedBy'
			ALTER TABLE asset.Project DROP COLUMN CreatedBy

			

			-- CHANGE SCHEMA FOR STORED PROCEDURES RELATED TO THE TABLES IN THE NEW ASSET SCHEMA

			DECLARE Proc_Cursor CURSOR FOR  
			SELECT ROUTINE_SCHEMA + '.' + ROUTINE_NAME  AS t
			FROM INFORMATION_SCHEMA.ROUTINES
			WHERE ROUTINE_SCHEMA = 'dbo'
			AND (ROUTINE_NAME LIKE 'ctcsp_Projects_%'
			OR ROUTINE_NAME LIKE 'ctcsp_ProjectPaths%'
			OR ROUTINE_NAME LIKE 'ctcsp_SchemaData%')

			OPEN Proc_Cursor;  
			FETCH NEXT FROM Proc_Cursor INTO @Name;  
			WHILE @@FETCH_STATUS = 0
			   BEGIN  
				  SET @Sql = 'ALTER SCHEMA asset TRANSFER ' + @Name + ';'
				  print 'Global - Transferring stored procedure ' + @Name + ' to schema: asset';
				  exec (@Sql);
				  FETCH NEXT FROM Proc_Cursor INTO @Name;
			   END;  
			CLOSE Proc_Cursor;  
			DEALLOCATE Proc_Cursor;  


			-- Stored procs will be updated below, after relationships are rebuilt
			-- using ints instead of guids.


		END  -- Updating Global Things (e.g. asset schema) 

	IF @palvers = 3
		---------------------------------------------------------------------------------------------------------------------------------------------
		-- MAKE CHANGES TO PAL SCHEMA TO UPGRADE FROM VERSION 3 TO VERSION 4
		---------------------------------------------------------------------------------------------------------------------------------------------
		BEGIN

			PRINT ''
			PRINT 'Updating PAL items from schema version 3 to version 4'

			
			-- This table is no longer used
			IF OBJECT_ID('dbo.LogChanges', 'U') IS NOT NULL 
				BEGIN
				
					PRINT 'PAL - Dropping table LogChanges'
					DROP TABLE dbo.LogChanges; 				
					
				END

			
			-- CHANGE THE SCHEMA FOR THE TABLES USED TO STORE PAL DATA TO THE NEW PAL SCHEMA 

			DECLARE @CT INT;
			DECLARE Table_Cursor CURSOR FOR  
			SELECT TABLE_SCHEMA + '.' + TABLE_NAME  AS t
			FROM INFORMATION_SCHEMA.TABLES 
			WHERE TABLE_SCHEMA = 'dbo'
			AND (TABLE_NAME LIKE 'Log%' 
			OR TABLE_NAME LIKE 'ctcvw%');

			OPEN Table_Cursor;  
			FETCH NEXT FROM Table_Cursor INTO @Name;  
			WHILE @@FETCH_STATUS = 0
			   BEGIN 
				  SET @Sql = 'ALTER SCHEMA pal TRANSFER ' + @Name + ';'
				  print 'PAL - Transferring table ' + @Name + ' to schema: pal';
				  exec (@Sql); 
				  FETCH NEXT FROM Table_Cursor INTO @Name; 
			   END;  
			CLOSE Table_Cursor;  
			DEALLOCATE Table_Cursor;  


			-- CHANGE THE SCHEMA FOR STORED PROCEDURES USED BY PAL TO USE THE NEW PAL SCHEMA

			DECLARE Proc_Cursor CURSOR FOR  
			SELECT ROUTINE_SCHEMA + '.' + ROUTINE_NAME  AS t
			FROM INFORMATION_SCHEMA.ROUTINES
			WHERE ROUTINE_SCHEMA = 'dbo'
			AND (ROUTINE_NAME LIKE 'ctcfn%'
			OR ROUTINE_NAME LIKE 'ctcsp_Get%'
			OR ROUTINE_NAME LIKE 'ctcsp_Upd%'
			OR ROUTINE_NAME LIKE 'ctcsp_LogDoc%'
			OR ROUTINE_NAME LIKE 'ctcsp_ProjectFileSnapshotOrLog%')

			OPEN Proc_Cursor;  
			FETCH NEXT FROM Proc_Cursor INTO @Name;  
			WHILE @@FETCH_STATUS = 0
			   BEGIN  
				  SET @Sql = 'ALTER SCHEMA pal TRANSFER ' + @Name + ';'
				  print 'PAL - Transferring stored procedure ' + @Name + ' to schema: pal';
				  exec (@Sql);
				  FETCH NEXT FROM Proc_Cursor INTO @Name;
			   END;  
			CLOSE Proc_Cursor;  
			DEALLOCATE Proc_Cursor;  

			
			-- CHANGE TABLE NAMES FROM PLURAL TO SINGULAR
			
			PRINT ''
			PRINT 'Start PAL table name changes to singular'

			PRINT 'Renaming Table LogAddIns to LogAddIn'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogAddIns' )
			BEGIN
					EXEC ('sp_rename ''pal.LogAddIns'', ''LogAddIn''');
			END

			PRINT 'Renaming Table LogCrashes to LogCrash'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogCrashes' )
			BEGIN
					EXEC ('sp_rename ''pal.LogCrashes'', ''LogCrash''');
			END

			PRINT 'Renaming Table LogDocSessions to LogDocSession'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogDocSessions' )
			BEGIN
					EXEC ('sp_rename ''pal.LogDocSessions'', ''LogDocSession''');
			END

			PRINT 'Renaming Table LogDocumentProjChanges to LogDocumentProjChange'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogDocumentProjChanges' )
			BEGIN
					EXEC ('sp_rename ''pal.LogDocumentProjChanges'', ''LogDocumentProjChange''');
			END

			PRINT 'Renaming Table LogElements to LogElement'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogElements' )
			BEGIN
					EXEC ('sp_rename ''pal.LogElements'', ''LogElement''');
			END

			PRINT 'Renaming Table LogEvents to LogEvent'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogEvents' )
			BEGIN
					EXEC ('sp_rename ''pal.LogEvents'', ''LogEvent''');
			END

			PRINT 'Renaming Table LogLinks to LogLink'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogLinks' )
			BEGIN
					EXEC ('sp_rename ''pal.LogLinks'', ''LogLink''');
			END

			PRINT 'Renaming Table LogMachines to LogMachine'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogMachines' )
			BEGIN
					EXEC ('sp_rename ''pal.LogMachines'', ''LogMachine''');
			END

			PRINT 'Renaming Table LogSummaries to LogSummary'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogSummaries' )
			BEGIN
					EXEC ('sp_rename ''pal.LogSummaries'', ''LogSummary''');
			END

			PRINT 'Renaming Table LogViewTypes to LogViewType'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogViewTypes' )
			BEGIN
					EXEC ('sp_rename ''pal.LogViewTypes'', ''LogViewType''');
			END

			PRINT 'Renaming Table LogWarnings to LogWarning'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogWarnings' )
			BEGIN
					EXEC ('sp_rename ''pal.LogWarnings'', ''LogWarning''');
			END
			PRINT 'End table name singularization'
			-- End pluralization removal

			
			PRINT ''
			PRINT 'PAL - Begin Add Columns'

			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogDocSession]') 
						AND name = 'CompanyID'
			)
			BEGIN
				PRINT 'PAL - Adding CompanyID to LogDocSession'
				ALTER TABLE pal.LogDocSession
				ADD CompanyID [int] NOT NULL DEFAULT 1
			END	
			
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogDocSession]') 
						AND name = 'LocalTimeOffset'
			)
			BEGIN
				PRINT 'PAL - Adding LocalTimeOffset to LogDocSession'
				ALTER TABLE pal.LogDocSession
				ADD LocalTimeOffset [float] NOT NULL DEFAULT 0
			END

			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogDocSession]') 
						AND name = 'MachineName'
			)
			BEGIN
				PRINT 'PAL - Adding MachineName to LogDocSession'
				ALTER TABLE pal.LogDocSession
				ADD MachineName [NVARCHAR](255) NULL
			END

			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogDocSession]') 
						AND name = 'BasePoint'
			)
			BEGIN
				PRINT 'PAL - Adding BasePoint to LogDocSession'
				ALTER TABLE pal.LogDocSession
				ADD BasePoint [NVARCHAR](50) NULL
			END

			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogDocSession]') 
						AND name = 'SurveyPoint'
			)
			BEGIN
				PRINT 'PAL - Adding SurveyPoint to LogDocSession'
				ALTER TABLE pal.LogDocSession
				ADD SurveyPoint [NVARCHAR](50) NULL
			END

			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogDocSession]') 
						AND name = 'AngleToTrueNorth'
			)
			BEGIN
				PRINT 'PAL - Adding AngleToTrueNorth to LogDocSession'
				ALTER TABLE pal.LogDocSession
				ADD AngleToTrueNorth [float] NULL
			END
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'ActionCt'
			)
			BEGIN
				PRINT 'PAL - Adding ActionCt to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD ActionCt [int]
			END	
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'ActiveWorksetName'
			)
			BEGIN
				PRINT 'PAL - Adding ActiveWorksetName to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD ActiveWorksetName [NVARCHAR](255) NULL
			END	
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'FamilyWorksetOpenCt'
			)
			BEGIN
				PRINT 'PAL - Adding FamilyWorksetOpenCt to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD FamilyWorksetOpenCt [int]
			END	
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'FamilyWorksetEditCt'
			)
			BEGIN
				PRINT 'PAL - Adding FamilyWorksetEditCt to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD FamilyWorksetEditCt [int]
			END	
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'StandardWorksetOpenCt'
			)
			BEGIN
				PRINT 'PAL - Adding StandardWorksetOpenCt to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD StandardWorksetOpenCt [int]
			END	
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'StandardWorksetEditCt'
			)
			BEGIN
				PRINT 'PAL - Adding StandardWorksetEditCt to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD StandardWorksetEditCt [int]
			END	
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'UserWorksetOpenCt'
			)
			BEGIN
				PRINT 'PAL - Adding UserWorksetOpenCt to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD UserWorksetOpenCt [int]
			END	
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'UserWorksetEditCt'
			)
			BEGIN
				PRINT 'PAL - Adding UserWorksetEditCt to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD UserWorksetEditCt [int]
			END	
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'ViewWorksetOpenCt'
			)
			BEGIN
				PRINT 'PAL - Adding ViewWorksetOpenCt to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD ViewWorksetOpenCt [int]
			END	
			
			IF NOT EXISTS (
				SELECT * 
				FROM   sys.columns 
				WHERE  object_id = OBJECT_ID(N'[pal].[LogEvent]') 
						AND name = 'ViewWorksetEditCt'
			)
			BEGIN
				PRINT 'PAL - Adding ViewWorksetEditCt to LogEvent'
				ALTER TABLE pal.LogEvent
				ADD ViewWorksetEditCt [int]
			END	
			
			PRINT ''
			PRINT 'PAL - End Add Columns'
			PRINT ''

	
		END   -- Upgrading PAL schema from version 3 to version 4

	IF @snapvers = 3
		---------------------------------------------------------------------------------------------------------------------------------------------
		-- MAKE CHANGES TO SNAPSHOT SCHEMA TO UPGRADE FROM VERSION 3 TO VERSION 4
		---------------------------------------------------------------------------------------------------------------------------------------------
		BEGIN

			PRINT ''
			PRINT 'Updating Snapshot items from schema version 3 to version 4'


			-- DELETE SNAPSHOT STORED PROCEDURES THAT ARE NO LONGER NEEDED

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_ReadByProjectFileSnapshotID_ElementDefinitionElementID')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementInstance_ReadByProjectFileSnapshotID_ElementDefinitionElementID'	
				DROP PROCEDURE [dbo].ctcsp_ElementInstance_ReadByProjectFileSnapshotID_ElementDefinitionElementID
			END
				
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_ReadByProjectFileSnapshotID_ElementDefinitionID')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementInstance_ReadByProjectFileSnapshotID_ElementDefinitionID'
				DROP PROCEDURE [dbo].ctcsp_ElementInstance_ReadByProjectFileSnapshotID_ElementDefinitionID
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_ReadByProjectFileSnapshotID_ElementTypeID')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementInstance_ReadByProjectFileSnapshotID_ElementTypeID'
				DROP PROCEDURE [dbo].ctcsp_ElementInstance_ReadByProjectFileSnapshotID_ElementTypeID
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementType_ReadBySnapshotID_ElementDefinitionElementID')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementType_ReadBySnapshotID_ElementDefinitionElementID'
				DROP PROCEDURE [dbo].ctcsp_ElementType_ReadBySnapshotID_ElementDefinitionElementID
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_AnyTable_Unpivot_ReadById')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_AnyTable_Unpivot_ReadById'
				DROP PROCEDURE [dbo].ctcsp_AnyTable_Unpivot_ReadById
			END
				
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_AnyTable_Unpivot_ReadNamedDateRange')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_AnyTable_Unpivot_ReadNamedDateRange'
				DROP PROCEDURE [dbo].ctcsp_AnyTable_Unpivot_ReadNamedDateRange
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_AnyTable_Unpivot_ReadNamedDateRange2')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_AnyTable_Unpivot_ReadNamedDateRange2'
				DROP PROCEDURE [dbo].ctcsp_AnyTable_Unpivot_ReadNamedDateRange2
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Discipline_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Discipline_Create'
				DROP PROCEDURE [dbo].ctcsp_Discipline_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Discipline_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Discipline_Delete'
				DROP PROCEDURE [dbo].ctcsp_Discipline_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Discipline_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Discipline_Update'
				DROP PROCEDURE [dbo].ctcsp_Discipline_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementDefinition_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementDefinition_Create'
				DROP PROCEDURE [dbo].ctcsp_ElementDefinition_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementDefinition_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementDefinition_Delete'
				DROP PROCEDURE [dbo].ctcsp_ElementDefinition_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementDefinition_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementDefinition_Update'
				DROP PROCEDURE [dbo].ctcsp_ElementDefinition_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementInstance_Create'
				DROP PROCEDURE [dbo].ctcsp_ElementInstance_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementInstance_Delete'
				DROP PROCEDURE [dbo].ctcsp_ElementInstance_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementInstance_Update'
				DROP PROCEDURE [dbo].ctcsp_ElementInstance_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementParameterValue_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementParameterValue_Create'
				DROP PROCEDURE [dbo].ctcsp_ElementParameterValue_Create
			END
				
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementParameterValue_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementParameterValue_Delete'
				DROP PROCEDURE [dbo].ctcsp_ElementParameterValue_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementParameterValue_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementParameterValue_Update'
				DROP PROCEDURE [dbo].ctcsp_ElementParameterValue_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementType_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementType_Create'
				DROP PROCEDURE [dbo].ctcsp_ElementType_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementType_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementType_Delete'
				DROP PROCEDURE [dbo].ctcsp_ElementType_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementType_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ElementType_Update'
				DROP PROCEDURE [dbo].ctcsp_ElementType_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstance_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstance_Create'
				DROP PROCEDURE [dbo].ctcsp_GroupInstance_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstance_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstance_Delete'
				DROP PROCEDURE [dbo].ctcsp_GroupInstance_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstance_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstance_Update'
				DROP PROCEDURE [dbo].ctcsp_GroupInstance_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstanceElementInstanceLookup_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstanceElementInstanceLookup_Create'
				DROP PROCEDURE [dbo].ctcsp_GroupInstanceElementInstanceLookup_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstanceElementInstanceLookup_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstanceElementInstanceLookup_Delete'
				DROP PROCEDURE [dbo].ctcsp_GroupInstanceElementInstanceLookup_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstanceElementInstanceLookup_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstanceElementInstanceLookup_Update'
				DROP PROCEDURE [dbo].ctcsp_GroupInstanceElementInstanceLookup_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstanceParameterValue_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstanceParameterValue_Create'
				DROP PROCEDURE [dbo].ctcsp_GroupInstanceParameterValue_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstanceParameterValue_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstanceParameterValue_Delete'
				DROP PROCEDURE [dbo].ctcsp_GroupInstanceParameterValue_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstanceParameterValue_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstanceParameterValue_Update'
				DROP PROCEDURE [dbo].ctcsp_GroupInstanceParameterValue_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_LinePattern_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_LinePattern_Create'
				DROP PROCEDURE [dbo].ctcsp_LinePattern_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_LinePattern_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_LinePattern_Delete'
				DROP PROCEDURE [dbo].ctcsp_LinePattern_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_LinePattern_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_LinePattern_Update'
				DROP PROCEDURE [dbo].ctcsp_LinePattern_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectFile_Create'
				DROP PROCEDURE [dbo].ctcsp_ProjectFile_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectFile_Delete'
				DROP PROCEDURE [dbo].ctcsp_ProjectFile_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectFile_Update'
				DROP PROCEDURE [dbo].ctcsp_ProjectFile_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshot_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectFileSnapshot_Create'
				DROP PROCEDURE [dbo].ctcsp_ProjectFileSnapshot_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshot_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectFileSnapshot_Delete'
				DROP PROCEDURE [dbo].ctcsp_ProjectFileSnapshot_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshot_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectFileSnapshot_Update'
				DROP PROCEDURE [dbo].ctcsp_ProjectFileSnapshot_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectInfoParameter_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectInfoParameter_Delete'
				DROP PROCEDURE [dbo].ctcsp_ProjectInfoParameter_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterCategory_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectParameterCategory_Create'
				DROP PROCEDURE [dbo].ctcsp_ProjectParameterCategory_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterCategory_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectParameterCategory_Delete'
				DROP PROCEDURE [dbo].ctcsp_ProjectParameterCategory_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterCategory_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectParameterCategory_Update'
				DROP PROCEDURE [dbo].ctcsp_ProjectParameterCategory_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterDefinition_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectParameterDefinition_Create'
				DROP PROCEDURE [dbo].ctcsp_ProjectParameterDefinition_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterDefinition_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectParameterDefinition_Delete'
				DROP PROCEDURE [dbo].ctcsp_ProjectParameterDefinition_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterDefinition_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectParameterDefinition_Update'
				DROP PROCEDURE [dbo].ctcsp_ProjectParameterDefinition_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectUnusedItem_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectUnusedItem_Create'
				DROP PROCEDURE [dbo].ctcsp_ProjectUnusedItem_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectUnusedItem_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectUnusedItem_Delete'
				DROP PROCEDURE [dbo].ctcsp_ProjectUnusedItem_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectUnusedItem_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectUnusedItem_Update'
				DROP PROCEDURE [dbo].ctcsp_ProjectUnusedItem_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Schedule_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Schedule_Create'
				DROP PROCEDURE [dbo].ctcsp_Schedule_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Schedule_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Schedule_Delete'
				DROP PROCEDURE [dbo].ctcsp_Schedule_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Schedule_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Schedule_Update'
				DROP PROCEDURE [dbo].ctcsp_Schedule_Update
			END
				
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ScheduleField_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ScheduleField_Create'
				DROP PROCEDURE [dbo].ctcsp_ScheduleField_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ScheduleField_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ScheduleField_Delete'
				DROP PROCEDURE [dbo].ctcsp_ScheduleField_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ScheduleField_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ScheduleField_Update'
				DROP PROCEDURE [dbo].ctcsp_ScheduleField_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_SchemaData_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_SchemaData_Update'
				DROP PROCEDURE [asset].ctcsp_SchemaData_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Warning_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Warning_Create'
				DROP PROCEDURE [dbo].ctcsp_Warning_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Warning_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Warning_Delete'
				DROP PROCEDURE [dbo].ctcsp_Warning_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Warning_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Warning_Update'
				DROP PROCEDURE [dbo].ctcsp_Warning_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Workset_Create')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Workset_Create'
				DROP PROCEDURE [dbo].ctcsp_Workset_Create
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Workset_Delete')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Workset_Delete'
				DROP PROCEDURE [dbo].ctcsp_Workset_Delete
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Workset_Update')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_Workset_Update'
				DROP PROCEDURE [dbo].ctcsp_Workset_Update
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterCategory_ReadByName_ProjectFileSnapshotID')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectParameterCategory_ReadByName_ProjectFileSnapshotID'
				DROP PROCEDURE [dbo].ctcsp_ProjectParameterCategory_ReadByName_ProjectFileSnapshotID
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterCategory_ReadByName_ProjectFileSnapshotID_SPGUID')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ProjectParameterCategory_ReadByName_ProjectFileSnapshotID_SPGUID'
				DROP PROCEDURE [dbo].ctcsp_ProjectParameterCategory_ReadByName_ProjectFileSnapshotID_SPGUID
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstanceParameterValue_ReadByGroupInstanceElementID_SnapshotID')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_GroupInstanceParameterValue_ReadByGroupInstanceElementID_SnapshotID'
				DROP PROCEDURE [dbo].ctcsp_GroupInstanceParameterValue_ReadByGroupInstanceElementID_SnapshotID
			END

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ScheduleField_ReadByScheduleElementID_ProjectFileSnapshotID')
			BEGIN
				PRINT 'Snapshot - Dropping stored procedure ctcsp_ScheduleField_ReadByScheduleElementID_ProjectFileSnapshotID'
				DROP PROCEDURE [dbo].ctcsp_ScheduleField_ReadByScheduleElementID_ProjectFileSnapshotID
			END



				
			-- CHANGE THE SCHEMA FOR THE SNAPSHOT TABLES TO BE IN THE NEW SNAPSHOT SCHEMA

			DECLARE Table_Cursor CURSOR FOR  
			SELECT TABLE_SCHEMA + '.' + TABLE_NAME  AS t
			FROM INFORMATION_SCHEMA.TABLES 
			WHERE TABLE_SCHEMA = 'dbo'
			AND (TABLE_NAME NOT LIKE 'Log%' 
			AND TABLE_NAME NOT LIKE 'ctcvw%'
			AND TABLE_NAME != 'ProjectPaths'
			AND TABLE_NAME != 'Projects'
			AND TABLE_NAME NOT LIKE 'sys%');

			OPEN Table_Cursor;  
			FETCH NEXT FROM Table_Cursor INTO @Name;  
			WHILE @@FETCH_STATUS = 0
			   BEGIN 
				  SET @Sql = 'ALTER SCHEMA snapshot TRANSFER ' + @Name + ';'
				  print 'Snapshot - Transferring table ' + @Name + ' to schema: snapshot';
				  exec (@Sql); 
				  FETCH NEXT FROM Table_Cursor INTO @Name; 
			   END;  
			CLOSE Table_Cursor;  
			DEALLOCATE Table_Cursor;  



			-- CHANGE THE SCHEMA FOR SNAPSHOT STORED PROCEDURES TO BE IN THE NEW SNAPSHOT SCHEMA 

			DECLARE Proc_Cursor CURSOR FOR  
			SELECT ROUTINE_SCHEMA + '.' + ROUTINE_NAME  AS t
			FROM INFORMATION_SCHEMA.ROUTINES
			WHERE ROUTINE_SCHEMA = 'dbo'
			AND (ROUTINE_NAME NOT LIKE 'ctcfn%'
			AND ROUTINE_NAME NOT LIKE 'ctcsp_Get%'
			AND ROUTINE_NAME NOT LIKE 'ctcsp_Upd%'
			AND ROUTINE_NAME NOT LIKE 'ctcsp_LogDoc%'
			AND ROUTINE_NAME NOT LIKE 'ctcsp_ProjectFileSnapshotOrLog%')

			OPEN Proc_Cursor;  
			FETCH NEXT FROM Proc_Cursor INTO @Name;  
			WHILE @@FETCH_STATUS = 0
			   BEGIN  
				  SET @Sql = 'ALTER SCHEMA snapshot TRANSFER ' + @Name + ';'
				  print 'Snapshot - Transferring stored procedure ' + @Name + ' to schema: snapshot';
				  exec (@Sql);
				  FETCH NEXT FROM Proc_Cursor INTO @Name;
			   END;  
			CLOSE Proc_Cursor;  
			DEALLOCATE Proc_Cursor;  


			-- MAKE TABLE SCHEMA CHANGES

			PRINT 'Add CompanyID field to the ProjectFile table.'

			IF NOT EXISTS (
			  SELECT * 
			  FROM   sys.columns 
			  WHERE  object_id = OBJECT_ID(N'[snapshot].[ProjectFile]') 
					 AND name = 'CompanyID'
			)
			BEGIN
				   ALTER TABLE snapshot.ProjectFile
				   ADD CompanyID INT NOT NULL DEFAULT(1)
			END


			PRINT 'Change the primary key on the ProjectFile table to include the new CompanyID field.'

			ALTER TABLE snapshot.ProjectFile
			DROP CONSTRAINT PK_ProjectFile

			ALTER TABLE snapshot.ProjectFile
			ADD CONSTRAINT PK_ProjectFile PRIMARY KEY (CompanyID,CentralOrSingleUserProjectFileName)


			PRINT 'Add CompanyID field to the ProjectFileSnapshot table.'

			IF NOT EXISTS (
			  SELECT * 
			  FROM   sys.columns 
			  WHERE  object_id = OBJECT_ID(N'[snapshot].[ProjectFileSnapshot]') 
					 AND name = 'CompanyID'
			)
			BEGIN
				   ALTER TABLE snapshot.ProjectFileSnapshot
				   ADD CompanyID INT NOT NULL DEFAULT(1)
			END

			
			PRINT 'Add SnapshotDateAndTimeUTC field to the ProjectFileSnapshot table.'

			IF NOT EXISTS (
			  SELECT * 
			  FROM   sys.columns 
			  WHERE  object_id = OBJECT_ID(N'[snapshot].[ProjectFileSnapshot]') 
					 AND name = 'SnapshotDateAndTimeUTC'
			)
			BEGIN
				   ALTER TABLE snapshot.ProjectFileSnapshot
				   ADD SnapshotDateAndTimeUTC datetime NULL 
			END
			

		END   -- Upgrading Snapshot schema from version 3 to version 4

	IF @palvers = 3 
		BEGIN

		---------------------------------------------------------------------------------------------------------------------------------------------
		--  UPDATE THE PAL TABLES CONVERT TO INT ID FIELDS AND REBUILD RELATIONSHIPS
		---------------------------------------------------------------------------------------------------------------------------------------------
		
		---------------------------------------------------------------------------------------------------------------------------------------------
		-- MUST UPDATE THE PAL STORED PROCEDURES TO USE THE NEW PAL SCHEMA
		---------------------------------------------------------------------------------------------------------------------------------------------

			PRINT 'Begin PAL stored procedures'	
			PRINT ' '
			PRINT 'PAL - Updating ctcsp_Get_CurrentActivitySchemaVersion'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_CurrentActivitySchemaVersion' )
				DROP PROCEDURE [pal].ctcsp_Get_CurrentActivitySchemaVersion
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_CurrentActivitySchemaVersion]
			(
				@SchemaVersion int OUTPUT 
			)
			AS
			BEGIN
				SET NOCOUNT ON;

				SELECT TOP 1 @SchemaVersion = CurrentActivitySchemaVersion
				FROM asset.SchemaData

			RETURN @SchemaVersion
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithConflictingProjectIds'	
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithConflictingProjectIds' )
			   DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithConflictingProjectIds
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithConflictingProjectIds] 
			(
				@p_CompanyID int
			)
			AS
			BEGIN
				-- SET NOCOUNT ON is added to prevent extra result sets from
				-- interfering with SELECT statements.
				SET NOCOUNT ON;

				SELECT  s.Id, 
						s.CentralFileName, 
						s.ShortFileName, 
						s.ProjectId AS DocProjectID, 
						asset.Project.ProjectNumber AS DocProjectNumber, 
						pp.ProjectId AS ProjProjectID, 
						pr.ProjectNumber AS ProjProjectNumber, 
						s.DocDateTime, 
						pp.DateCreated AS ProjDateTime, 
						s.CompanyID
				FROM    pal.LogDocSession AS s
					INNER JOIN asset.ProjectPath AS pp
						ON	LEFT(s.CentralFileName, LEN(s.CentralFileName) - CHARINDEX(''\'', REVERSE(s.CentralFileName), 1)) = pp.CentralFilePath 
							AND s.ProjectId <> pp.ProjectId 
							INNER JOIN asset.Project AS pr ON pp.ProjectId = pr.Id 
							INNER JOIN asset.Project ON s.ProjectId = asset.Project.Id
				WHERE   (s.CompanyID = @p_CompanyID)
				ORDER BY s.CentralFileName, s.ProjectId, s.DocDateTime, pp.DateCreated
			
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithDeletedProjectIds'	
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithDeletedProjectIds' )
			   DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithDeletedProjectIds
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithDeletedProjectIds] 
			(
				@p_CompanyID int
			)
			AS
			BEGIN
			SET NOCOUNT ON;
			
				SELECT 
					s.Id,
					s.CentralFileName, 
					s.ShortFileName,
					s.ProjectId AS DocProjectID,
					''deleted'' AS DocProjectNumber,
					pp.ProjectId AS ProjProjectID, 
					pr.ProjectNumber AS ProjProjectNumber,
					s.DocDateTime,
					pp.DateCreated AS ProjDateTime
				FROM pal.LogDocSession AS s
				LEFT JOIN asset.Project As p ON p.Id = s.ProjectId 
				INNER JOIN asset.ProjectPath As pp 
					ON LEFT(s.CentralFileName, LEN(s.CentralFileName) - CHARINDEX(''\'', REVERSE(s.CentralFileName), 1)) = pp.CentralFilePath
				INNER JOIN asset.Project AS pr ON pp.ProjectId = pr.Id 
				WHERE   (s.CompanyID = @p_CompanyID) 
				AND		(p.Id IS NULL)
				ORDER BY CentralFileName, DocProjectID, DocDateTime,ProjDateTime
			END ');
				
				
				
			PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithEmptyProjectIds'	
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithEmptyProjectIds' )
			   DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithEmptyProjectIds
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithEmptyProjectIds] 
			(
				@p_CompanyID int
			)
			AS
			BEGIN
				-- SET NOCOUNT ON is added to prevent extra result sets from
				-- interfering with SELECT statements.
				SET NOCOUNT ON;

			SELECT  
				s.Id,       
				s.CentralFileName, 
				s.ShortFileName, 
				s.ProjectId AS DocProjectID, 
				asset.Project.ProjectNumber AS DocProjectNumber, 
				pp.ProjectId AS ProjProjectID, 
				pr.ProjectNumber AS ProjProjectNumber, 
				s.DocDateTime,
				pp.DateCreated AS ProjDateTime,
				s.CompanyID
			FROM pal.LogDocSession AS s
				INNER JOIN
					asset.ProjectPath As pp ON 
					LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath
					AND s.ProjectId <> pp.ProjectId 

				INNER JOIN asset.Project AS pr ON pp.ProjectId = pr.Id 
				INNER JOIN asset.Project ON s.ProjectId = asset.Project.Id
			WHERE (s.CompanyID = @p_CompanyID) 
			AND   (s.ProjectId = ''00000000-0000-0000-0000-000000000000'')
			ORDER BY CentralFileName, DocProjectID, DocDateTime,ProjDateTime
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithNoProject'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithNoProject' )
			   DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithNoProject
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithNoProject] 
			(
				@p_CompanyID int
			)	
			AS
			BEGIN
				-- SET NOCOUNT ON is added to prevent extra result sets from
				-- interfering with SELECT statements.
				SET NOCOUNT ON;

			SELECT distinct
				LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) As CentralFileName
			FROM pal.LogDocSession AS s 
				LEFT OUTER JOIN asset.Project AS pr 
				INNER JOIN asset.ProjectPath AS pp ON pr.Id = pp.ProjectId 
				ON LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath 
				AND s.ProjectId <> pp.ProjectId
			WHERE (s.CompanyID = @p_CompanyID) 
			AND (s.ProjectId = ''00000000-0000-0000-0000-000000000000'') 
			AND (pp.ProjectId IS NULL)
			ORDER BY CentralFileName

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds' )
			   DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds] 
			(
				@p_CompanyID int
			)	
			AS
			BEGIN
				-- SET NOCOUNT ON is added to prevent extra result sets from
				-- interfering with SELECT statements.
				SET NOCOUNT ON;

				SELECT        
					s.Id,
					s.CentralFileName,
					s.ShortFileName, 
					s.ProjectId AS DocProjectID, 
					asset.Project.ProjectNumber AS DocProjectNumber, 
					pp.ProjectId AS ProjProjectID,
					pr.ProjectNumber AS ProjProjectNumber, 
					s.DocDateTime,
					pp.DateCreated AS ProjDateTime
				FROM pal.LogDocSession As s
					INNER JOIN
						asset.ProjectPath As pp
						ON LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath 
						AND s.ProjectId <> pp.ProjectId 
					INNER JOIN asset.Project AS pr ON pp.ProjectId = pr.Id 
					INNER JOIN asset.Project ON s.ProjectId = asset.Project.Id
				WHERE (s.CompanyID = @p_CompanyID) 
				AND (s.ProjectId <> ''00000000-0000-0000-0000-000000000000'')
				ORDER BY CentralFileName, DocProjectID, DocDateTime,ProjDateTime

			END' );

			
			
			PRINT 'PAL - Updating ctcsp_Get_MappedProjectPathsFromLogDocSessions'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_MappedProjectPathsFromLogDocSessions' )
			   DROP PROCEDURE [pal].ctcsp_Get_MappedProjectPathsFromLogDocSessions
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_MappedProjectPathsFromLogDocSessions] 
			(
				@p_CompanyID int
			)	
			AS
			BEGIN

				SELECT DISTINCT
					pp.Id
					,LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) As CentralFileName
					,pr.ProjectNumber AS DocProjectNumber
					,pr.Id AS DocProjectID
				FROM pal.LogDocSession AS s 
					LEFT OUTER JOIN asset.Project AS pr 
					INNER JOIN asset.ProjectPath AS pp ON pr.Id = pp.ProjectId 
					ON LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath 
				
				WHERE (s.CompanyID = @p_CompanyID) 
				AND   (pp.ProjectId IS NOT NULL)
				ORDER BY DocProjectNumber, CentralFileName

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_ProjectPaths'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_ProjectPaths' )
				DROP PROCEDURE [pal].[ctcsp_Get_ProjectPaths]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_ProjectPaths] 
			(
				@p_CompanyID int
			)	
			AS
			BEGIN

				SELECT pp.Id, 
				   pp.ProjectId, 
				   pp.UserName, 
				   pp.DateCreated, 
				   pp.CentralFilePath, 
				   pr.CompanyID
				FROM   asset.ProjectPath AS pp
				INNER JOIN asset.Project AS pr ON pp.ProjectId = pr.Id
				WHERE (CompanyID = @p_CompanyID) 
				ORDER BY [DateCreated]

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_ProjectPathsFromLogDocSessions'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_ProjectPathsFromLogDocSessions' )
				DROP PROCEDURE [pal].[ctcsp_Get_ProjectPathsFromLogDocSessions]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_ProjectPathsFromLogDocSessions]
			(
				@p_CompanyID int
			)	 
			AS
			BEGIN
			
				SET NOCOUNT ON;

				SELECT DISTINCT
					ISNULL(pp.Id, ''00000000-0000-0000-0000-000000000000'') AS Id
					,LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) As CentralFileName
					,ISNULL(pr.ProjectNumber, ''0'') AS DocProjectNumber
					,ISNULL(pr.Id, ''00000000-0000-0000-0000-000000000000'')  AS DocProjectID
				FROM pal.LogDocSession As s
					LEFT OUTER JOIN asset.Project AS pr 
					INNER JOIN asset.ProjectPath As pp ON pr.Id = pp.ProjectId 
					ON LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath 
					AND s.ProjectId <> pp.ProjectId
				WHERE (s.CompanyID = @p_CompanyID) 
				ORDER BY CentralFileName

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_Projects'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Projects' )
				DROP PROCEDURE [pal].[ctcsp_Get_Projects]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Projects] 
			(
				@p_CompanyID int
			)	
			AS
			BEGIN
			
				SET NOCOUNT ON;

				SELECT 
					   [Id]
					  ,[Project]
					  ,[Project Number]
					  ,[Project Name]
					  ,[Client Name]
					  ,[Issue Date]
					  ,[Days Until Issue]
					  ,[Office]
					  ,[BuildingName]
					  ,[ClientName]
					  ,[StreetAddress]
					  ,[StreetAddress2]
					  ,[StreetAddress3]
					  ,[ProjectStatus]
					  ,[Author]
					  ,[City]
					  ,[StateOrProvince]
					  ,[PostalCode]
					  ,[CountryName]
					  ,[OrgName]
					  ,[OrgDescription]
					  ,[DateCreated]
				FROM ctcvw_Project
				WHERE (ctcvw_Project.CompanyID = @p_CompanyID) 
				ORDER BY [Project Number]

			END ');

			
			
			
			PRINT 'PAL - Updating ctcsp_LogDocSessions_DeleteByDateAndCentralFileName'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_LogDocSessions_DeleteByDateAndCentralFileName' )
				DROP PROCEDURE [pal].[ctcsp_LogDocSessions_DeleteByDateAndCentralFileName]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_LogDocSessions_DeleteByDateAndCentralFileName]
			(
				@p_CompanyID int,
				@ItemName nvarchar(255),
				@DateFrom DateTime,
				@DateTo DateTime
			)
			AS
				SET NOCOUNT OFF;
			
			BEGIN
				IF (@ItemName = ''all'')
					BEGIN
						DELETE [pal].[LogDocSession] 
						FROM LogDocSession 
						WHERE (CompanyID = @p_CompanyID) 
						AND LogDocSession.DocDateTime BETWEEN @DateFrom AND @DateTo
					END
				ELSE
					BEGIN
							DELETE [pal].[LogDocSession] 
							FROM LogDocSession
							WHERE (CompanyID = @p_CompanyID) 
							AND LogDocSession.DocDateTime BETWEEN @DateFrom AND @DateTo
							AND CentralFileName = @ItemName
					END

				RETURN @@RowCount

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_LogDocSessions_UpdateHasClosed_ByUserAndMachineName'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_LogDocSessions_UpdateHasClosed_ByUserAndMachineName' )
				DROP PROCEDURE [pal].[ctcsp_LogDocSessions_UpdateHasClosed_ByUserAndMachineName]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_LogDocSessions_UpdateHasClosed_ByUserAndMachineName]
			(
				@p_CompanyID int,
				@UserName NVARCHAR(100),
				@MachineName NVARCHAR(255)
			
			)
			AS
				SET NOCOUNT OFF;
			
			BEGIN

				UPDATE pal.LogDocSession       
					SET HasClosed = 1
				FROM LogDocSession 
				INNER JOIN LogMachine As m ON LogDocSession.Id = m.DocSessionId
				WHERE (LogDocSession.CompanyID = @p_CompanyID) 
					AND (HasClosed = 0)
					AND  (UserName = @UserName)
					AND  (m.MachineName = @MachineName)
					AND (DocDateTime BETWEEN CAST(GETDATE() AS DATE) AND DATEADD(DAY, 1, CAST(GETDATE() AS DATE)))

				RETURN @@RowCount
			SET NOCOUNT ON;
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDate'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDate' )
				DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDate]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDate]
			(
				@p_CompanyID int,
				@DateFrom DateTime,
				@DateTo DateTime,
				@IsSnapshot bit
			)
			AS
				SET NOCOUNT OFF;
			
			BEGIN
				IF (@IsSnapshot = 0)
					DELETE d
					FROM pal.LogDocSession As d 
					WHERE (d.CompanyID = @p_CompanyID) 
					AND (d.DocDateTime BETWEEN @DateFrom AND @DateTo)
				ELSE
					DELETE p
					FROM snapshot.ProjectFileSnapshot As p
					WHERE (p.CompanyID = @p_CompanyID) 
					AND   (p.SnapshotDateAndTime BETWEEN @DateFrom AND @DateTo)

			RETURN @@RowCount

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDateAndProjectID'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDateAndProjectID' )
				DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDateAndProjectID]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDateAndProjectID]
			(
				@p_CompanyID int,
				@ProjectID uniqueidentifier,
				@DateFrom DateTime,
				@DateTo DateTime,
				@IsSnapshot bit
			)
			AS
				SET NOCOUNT OFF;
			
			BEGIN

				IF (@IsSnapshot = 0)
					DELETE s
					FROM pal.LogDocSession As s
					WHERE (s.CompanyID = @p_CompanyID)
					AND   (s.DocDateTime BETWEEN @DateFrom AND @DateTo)
					AND   (s.ProjectId = @ProjectID)
				ELSE
					DELETE ps
					FROM snapshot.ProjectFileSnapshot As ps
						INNER JOIN snapshot.ProjectFile ON ps.ProjectFileID = ProjectFile.ID 
					WHERE (ps.CompanyID = @p_CompanyID)
					AND   (ps.SnapshotDateAndTime BETWEEN @DateFrom AND @DateTo)
					AND   (ProjectFile.ProjectID = @ProjectID)

			RETURN @@RowCount

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadAll'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadAll' )
				DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadAll]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadAll]
			(
				@p_CompanyID int,
				@IsSnapshot bit
			)
			AS

			BEGIN

				SET NOCOUNT ON;
			
				IF (@IsSnapshot = 0)
					SELECT 
						NEWID() AS ItemID
						,Data.ProjectId AS ProjectID 
						,Data.CentralFileName AS ItemName
						,MIN(pr.ProjectNumber) AS ProjectNumber 
						,MIN(Data.DocDateTime) AS ItemDateTime
					FROM pal.LogDocSession AS Data 
					INNER JOIN asset.Project As pr ON Data.ProjectId = pr.Id
					WHERE (Data.CompanyID = @p_CompanyID)
					GROUP BY Data.ProjectId, Data.CentralFileName
					ORDER BY MIN(pr.ProjectNumber), ItemName, MIN(Data.DocDateTime)
				ELSE
					SELECT  
						pfs.ID AS ItemID
						,pf.ProjectID
						,p.ProjectNumber 
						,pfs.SnapshotName AS ItemName
						,pfs.SnapshotDateAndTime AS ItemDateTime
				
					FROM snapshot.ProjectFileSnapshot As pfs
						INNER JOIN snapshot.ProjectFile As pf ON pfs.ProjectFileID = pf.ID 
						INNER JOIN asset.Project As p ON pf.ProjectID = p.Id
					WHERE (pfs.CompanyID = @p_CompanyID)
					ORDER BY pfs.SnapshotDateAndTime
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDate'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDate' )
				DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDate]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDate]
			(
				@p_CompanyID int,
				@DateFrom DateTime,
				@DateTo DateTime,
				@IsSnapshot bit
			)
			AS

			BEGIN
			SET NOCOUNT ON;
				IF (@IsSnapshot = 0)
				
					SELECT 
						NEWID() AS ItemID
						,Data.ProjectId AS ProjectID 
						,Data.CentralFileName AS ItemName
						,MIN(pr.ProjectNumber) AS ProjectNumber 
						,MIN(Data.DocDateTime) AS ItemDateTime
					FROM pal.LogDocSession AS Data 
				
					INNER JOIN asset.Project As pr ON Data.ProjectId = pr.Id
					WHERE (Data.CompanyID = @p_CompanyID)
					AND Data.DocDateTime BETWEEN @DateFrom AND @DateTo
					GROUP BY Data.ProjectId, Data.CentralFileName
					ORDER BY MIN(pr.ProjectNumber), ItemName, MIN(Data.DocDateTime)
				ELSE
					SELECT  
						 pfs.ID AS ItemID
						,pf.ProjectID
						,pr.ProjectNumber 
						,pfs.SnapshotName AS ItemName
						,pfs.SnapshotDateAndTime AS ItemDateTime

					FROM snapshot.ProjectFileSnapshot As pfs
						INNER JOIN snapshot.ProjectFile As pf ON pfs.ProjectFileID = pf.ID 
						INNER JOIN asset.Project As pr ON pf.ProjectID = pr.Id
					WHERE (pfs.CompanyID = @p_CompanyID)
					AND   (pfs.SnapshotDateAndTime BETWEEN @DateFrom AND @DateTo)
					ORDER BY pfs.SnapshotDateAndTime
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDateAndProjectID'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDateAndProjectID' )
				DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDateAndProjectID]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDateAndProjectID]
			(
				@ProjectID uniqueidentifier = NULL,
				@DateFrom DateTime,
				@DateTo DateTime,
				@IsSnapshot bit
			)
			AS
			BEGIN

				SET NOCOUNT ON;
			
				IF (@IsSnapshot = 0)
					SELECT 
						NEWID() AS ItemID
						,Data.ProjectId AS ProjectID 
						,Data.CentralFileName AS ItemName
						,MIN(pr.ProjectNumber) AS ProjectNumber 
						,MIN(Data.DocDateTime) AS ItemDateTime
					FROM pal.LogDocSession AS Data 
					INNER JOIN asset.Project As pr ON Data.ProjectId = pr.Id
					WHERE Data.DocDateTime BETWEEN @DateFrom AND @DateTo
					AND ProjectId = @ProjectID
					GROUP BY Data.ProjectId, Data.CentralFileName
					ORDER BY MIN(pr.ProjectNumber), ItemName, MIN(Data.DocDateTime)
				ELSE
					SELECT  
						pfs.ID AS ItemID
						,pf.ProjectID
						,pr.ProjectNumber 
						,pfs.SnapshotName AS ItemName
						,pfs.SnapshotDateAndTime AS ItemDateTime

					FROM snapshot.ProjectFileSnapshot As pfs
						INNER JOIN snapshot.ProjectFile As pf ON pfs.ProjectFileID = pf.ID 
						INNER JOIN asset.Project As pr ON pf.ProjectID = pr.Id
					WHERE pfs.SnapshotDateAndTime BETWEEN @DateFrom AND @DateTo
					AND ProjectID = @ProjectID
					ORDER BY pfs.SnapshotDateAndTime
					
				END ');

				
				
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_Changes'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_Changes' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_Changes]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_Changes] 
			(
				@Id uniqueidentifier,
				@Added int,
				@Deleted int,
				@Modified int
			)
			AS

			BEGIN
			DECLARE @WarningCt int;
			SET NOCOUNT OFF;

			UPDATE pal.LogDocSession
			SET	
				ElemAddedCt = @Added,
				ElemDeletedCt = @Deleted,
				ElemModifiedCt = @Modified

			WHERE @Id = LogDocSession.Id
			SET NOCOUNT ON;

			return @@ROWCOUNT;
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_HasClosed'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_HasClosed' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_HasClosed]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_HasClosed] 
			(
				@Id uniqueidentifier
			)
			AS

			BEGIN

			SET NOCOUNT OFF;
			
			UPDATE pal.LogDocSession
			SET	[HasClosed] = 1
			WHERE @Id = LogDocSession.Id

			SET NOCOUNT ON;

			return @@ROWCOUNT;
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds] 
			(
				@p_CompanyID int,
				@p_UserName NVARCHAR(100)
			)
			AS
			BEGIN

				SET NOCOUNT ON;

				INSERT INTO pal.LogDocumentProjChange(
					 [Id]
					,[DocSessionId]
					,[CentralFileName]
					,[UserName]
					,[OldProjectId]
					,[NewProjectId]
					,[DateCreated])
				SELECT NEWID(), ds.Id, ds.CentralFileName, @p_UserName, ds.ProjectId, pp.ProjectId, GETUTCDATE()
				FROM pal.LogDocSession as ds
				INNER JOIN
					asset.ProjectPath as pp
					ON LEFT(ds.CentralFileName,LEN(ds.CentralFileName) - charindex(''\'',reverse(ds.CentralFileName),1)) = pp.CentralFilePath 
					AND ds.ProjectId <> pp.ProjectId 
					INNER JOIN asset.Project AS pr ON pp.ProjectId = pr.Id 
					INNER JOIN asset.Project ON ds.ProjectId = asset.Project.Id
				WHERE (ds.CompanyID = @p_CompanyID)
				AND   (ds.ProjectId <> ''00000000-0000-0000-0000-000000000000'')

				SET NOCOUNT OFF;

				UPDATE ds
				SET ds.ProjectId = pp.ProjectId
				FROM pal.LogDocSession as ds
				INNER JOIN
					asset.ProjectPath as pp
					ON LEFT(ds.CentralFileName,LEN(ds.CentralFileName) - charindex(''\'',reverse(ds.CentralFileName),1)) = pp.CentralFilePath 
					AND ds.ProjectId <> pp.ProjectId 
					INNER JOIN asset.Project AS pr ON pp.ProjectId = pr.Id 
					INNER JOIN asset.Project ON ds.ProjectId = asset.Project.Id
				WHERE (ds.CompanyID = @p_CompanyID)
				AND   (ds.ProjectId <> ''00000000-0000-0000-0000-000000000000'')

				Return @@ROWCOUNT;

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds] 
			(
				@p_CompanyID int
			)
			AS
			BEGIN

				SET NOCOUNT OFF;
				UPDATE t1
				SET t1.ProjectId = t2.ProjectId
				FROM pal.LogDocSession AS t1
				LEFT JOIN asset.Project As pr ON pr.Id = t1.ProjectId 
				INNER JOIN asset.ProjectPath AS t2
				ON LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = t2.CentralFilePath
				INNER JOIN asset.Project AS t3 ON t2.ProjectId = t3.Id
				WHERE (t1.CompanyID = @p_CompanyID)
				AND (pr.Id IS NULL)
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds] 
			(
				@p_CompanyID int,
				@p_UserName NVARCHAR(100)
			)
			AS
			BEGIN

				SET NOCOUNT ON;

				INSERT INTO pal.LogDocumentProjChange(
					 [Id]
					,[DocSessionId]
					,[CentralFileName]
					,[UserName]
					,[OldProjectId]
					,[NewProjectId]
					,[DateCreated])
				SELECT NEWID(), t1.Id, t1.CentralFileName, @p_UserName, t1.ProjectId, t2.ProjectId, GETUTCDATE()
				FROM pal.LogDocSession AS t1
					  INNER JOIN asset.ProjectPath AS t2
					  ON LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = t2.CentralFilePath
					  WHERE (t1.CompanyID = @p_CompanyID)
					  AND (t1.ProjectId = ''00000000-0000-0000-0000-000000000000'')

				SET NOCOUNT OFF;

				UPDATE t1
					  SET t1.ProjectId = t2.ProjectId
					  FROM pal.LogDocSession AS t1
					  INNER JOIN asset.ProjectPath AS t2
					  ON LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = t2.CentralFilePath
					  WHERE (t1.CompanyID = @p_CompanyID)
					  AND (t1.ProjectId = ''00000000-0000-0000-0000-000000000000'')

				Return @@ROWCOUNT;
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceProjectId'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceProjectId' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectId]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectId] 
			(
				@p_ID uniqueidentifier
				,@p_ProjectId uniqueidentifier
			)
			AS
			BEGIN
				-- SET NOCOUNT ON is added to prevent extra result sets from
				-- interfering with SELECT statements.

				-- Specify in which table the row exists to update
				UPDATE pal.LogDocSession
			
				-- Specify which parameter value goes into which fields
				SET ProjectId = @p_ProjectId
			
				-- Specify how to find which record to update
				WHERE Id = @p_ID

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath] 
			(
				@p_CompanyID int,
				@ProjectId uniqueIdentifier,
				@UserName NVARCHAR(100), 
				@Path NVARCHAR(255)
			) 
			AS
			BEGIN

				SET NOCOUNT ON;

				INSERT INTO pal.LogDocumentProjChange(
					 [Id]
					,[DocSessionId]
					,[CentralFileName]
					,[UserName]
					,[OldProjectId]
					,[NewProjectId]
					,[DateCreated])
				SELECT NEWID(), t1.Id, t1.CentralFileName, @UserName, t1.ProjectId, @ProjectId, GETUTCDATE()
				FROM pal.LogDocSession AS t1
				WHERE (t1.CompanyID = @p_CompanyID)
				AND LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = @Path;

				SET NOCOUNT OFF;

				UPDATE pal.LogDocSession
				SET ProjectId = @ProjectId
				WHERE (pal.LogDocSession.CompanyID = @p_CompanyID)
				AND LEFT(pal.LogDocSession.CentralFileName,LEN(pal.LogDocSession.CentralFileName) - charindex(''\'',reverse(pal.LogDocSession.CentralFileName),1)) = @Path;

				Return @@ROWCOUNT;
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_STC'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_STC' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_STC]
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_STC] 
			(
				@Id uniqueidentifier
			)
			AS
			BEGIN

			DECLARE @DocDate DateTime;
			SET NOCOUNT OFF;
			SELECT @DocDate = DocDateTime FROM pal.LogDocSession WHERE Id = @Id;

			UPDATE pal.LogDocSession
			SET	
			  [STCDuration] = x.EventDuration,
			  [STCDateTime] = x.EventDateTime,
			  [SessionHours] = ISNULL(CAST(DATEDIFF(MILLISECOND, @DocDate, x.EventDateTime) / 3600000.000 AS float), 0.0)

			FROM
			(
				SELECT  TOP 1 DocSessionId, EventId, EventDuration, EventDateTime
				FROM    pal.LogEvent
				WHERE   (EventName = N''SyncComplete'') AND DocSessionId = @Id
				ORDER BY EventId desc
			) x
			WHERE @Id = LogDocSession.Id

			RETURN @@ROWCOUNT;
			SET NOCOUNT ON;
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_Summary'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_Summary' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_Summary] 
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_Summary] 

				@Id uniqueidentifier,
				@GroupCt int,
				@InPlaceCt int,
				@UnPlacedRoomCt int,
				@UnenclosedRoomCt int,
				@PlacedRoomCt int,
				@UnPlacedSpaceCt int,
				@UnenclosedSpaceCt int,
				@PlacedSpaceCt int,
				@ViewCt int,
				@PhaseCt int,
				@DesOptCt int,
				@WorksetCt int,
				@FamilyCt int,
				@InstanceCt int,
				@UnplacedFamilyCt int,
				@MaterialCt int,
				@ViewFilterCt int,
				@LevelCt int

			AS
			BEGIN

			SET NOCOUNT OFF;
			-----------------------------------------------------------------------------
			-- Add Summary Info
			UPDATE pal.LogDocSession
			SET	
				GroupCt = @GroupCt,
				InPlaceCt = @InPlaceCt,
				UnPlacedRoomCt = @UnPlacedRoomCt,
				UnenclosedRoomCt = @UnenclosedRoomCt,
				PlacedRoomCt = @PlacedRoomCt,
				UnPlacedSpaceCt= ISNULL(@UnPlacedSpaceCt, 0),
				UnenclosedSpaceCt= ISNULL(@UnenclosedSpaceCt, 0),
				PlacedSpaceCt = ISNULL(@PlacedSpaceCt,0),
				ViewCt = @ViewCt,
				PhaseCt= @PhaseCt,
				DesOptCt= @DesOptCt,
				WorksetCt = @WorksetCt,
				FamilyCt = @FamilyCt,
				InstanceCt = @InstanceCt,
				UnplacedFamilyCt = @UnplacedFamilyCt,
				MaterialCt = @MaterialCt,
				ViewFilterCt = @ViewFilterCt,
				LevelCt = @LevelCt

			WHERE @Id = LogDocSession.Id

			RETURN @@ROWCOUNT;
			SET NOCOUNT ON;
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_Warnings'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_Warnings' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_Warnings] 
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_Warnings] 
			(
				@Id uniqueidentifier,
				@WarningCt int
			)
			AS

			BEGIN

			SET NOCOUNT OFF;
			UPDATE pal.LogDocSession
			SET	
				[WarningCt] = @WarningCt

			WHERE @Id = Id

			SET NOCOUNT ON;

			return @@ROWCOUNT;
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath' )
				DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath] 
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath] 
			(
				@p_CompanyID int,
				@ProjectId uniqueIdentifier,
				@UserName NVARCHAR(100), 
				@Path NVARCHAR(255)
			)
			AS
			BEGIN

				SET NOCOUNT ON;

				INSERT INTO pal.LogDocumentProjChange(
					 [Id]
					,[DocSessionId]
					,[CentralFileName]
					,[UserName]
					,[OldProjectId]
					,[NewProjectId]
					,[DateCreated])
				SELECT NEWID(), t1.Id, t1.CentralFileName, @UserName, t1.ProjectId, @ProjectId, GETUTCDATE()
				FROM pal.LogDocSession AS t1
				WHERE (t1.CompanyID = @p_CompanyID)
				AND LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = @Path;

				SET NOCOUNT OFF;

				UPDATE pal.LogDocSession
				SET ProjectId = @ProjectId
				WHERE (CompanyID = @p_CompanyID)
				AND LEFT(CentralFileName,LEN(CentralFileName) - charindex(''\'',reverse(CentralFileName),1)) = @Path;

				-- TODO: Add CompanyID
				UPDATE snapshot.ProjectFile
				SET ProjectID = @ProjectId
				WHERE LEFT(snapshot.ProjectFile.CentralOrSingleUserProjectFileName,LEN(snapshot.ProjectFile.CentralOrSingleUserProjectFileName) - charindex(''\'',reverse(snapshot.ProjectFile.CentralOrSingleUserProjectFileName),1)) = @Path COLLATE SQL_Latin1_General_CP1_CI_AS;

				SET NOCOUNT ON;

				Return @@ROWCOUNT;
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Upd_Projects_NonNull'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_Projects_NonNull' )
				DROP PROCEDURE [pal].[ctcsp_Upd_Projects_NonNull] 
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_Project_NonNull]
			(
				@Id uniqueidentifier,
				@Office nvarchar(50),
				@ProjectNumber nvarchar(50),
				@ProjectName nvarchar(255),
				@BuildingName nvarchar(100),
				@ClientName nvarchar(50),
				@StreetAddress nvarchar(100) = NULL ,
				@StreetAddress2 nvarchar(100),
				@StreetAddress3 nvarchar(100),
				@ProjectStatus nvarchar(25),
				@ProjectIssueDate nvarchar(24),
				@Author nvarchar(50),
				@City nvarchar(100),
				@StateOrProvince nvarchar(25),
				@PostalCode nvarchar(12),
				@CountryName nvarchar(35),
				@OrgName nvarchar(100),
				@OrgDescription nvarchar(2048),
				@LastUpdated datetime
			)

			AS
			BEGIN
				SET NOCOUNT OFF;

			UPDATE [asset].[Project] SET 
				[Office] = @Office,
				[ProjectNumber] = @ProjectNumber,
				[ProjectName] = CASE WHEN (@ProjectName = '''') THEN ProjectName ELSE @ProjectName END,
				[BuildingName] = (CASE WHEN (@BuildingName = '''') THEN BuildingName ELSE @BuildingName END),
				[ClientName] = (CASE WHEN (@ClientName = '''') THEN ClientName ELSE @ClientName END),
				[StreetAddress] = (CASE WHEN (@StreetAddress = '''') THEN StreetAddress ELSE @StreetAddress END),
				[StreetAddress2] = (CASE WHEN (@StreetAddress2 = '''') THEN StreetAddress2 ELSE @StreetAddress2 END),
				[StreetAddress3] = (CASE WHEN (@StreetAddress3 = '''') THEN StreetAddress3 ELSE @StreetAddress3 END),
				[ProjectStatus] = (CASE WHEN (@ProjectStatus = '''') THEN ProjectStatus ELSE @ProjectStatus END),
				[ProjectIssueDate] = (CASE WHEN (@ProjectIssueDate = '''') THEN ProjectIssueDate ELSE @ProjectIssueDate END),
				[Author] = (CASE WHEN (@Author = '''') THEN Author ELSE @Author END),
				[City] = (CASE WHEN (@City = '''') THEN City ELSE @City END),
				[StateOrProvince] = (CASE WHEN (@StateOrProvince = '''') THEN StateOrProvince ELSE @StateOrProvince END),
				[PostalCode] = (CASE WHEN (@PostalCode = '''') THEN PostalCode ELSE @PostalCode END),
				[CountryName] = (CASE WHEN (@CountryName = '''') THEN CountryName ELSE @CountryName END),
				[OrgName] = (CASE WHEN (@OrgName = '''') THEN OrgName ELSE @OrgName END),
				[OrgDescription] = (CASE WHEN (@OrgDescription = '''') THEN OrgDescription ELSE @OrgDescription END),
				LastUpdated = @LastUpdated

			WHERE (([Id] = @Id));

			END	');

			PRINT ''
			PRINT 'End PAL stored procedures'
			
			
			PRINT ''
			PRINT 'Begin PAL PowerBI stored procedures'
			PRINT ''
			
			
			PRINT 'PAL - Updating ctcsp_Get_STCs_ByNamedDateRange'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_STCs_ByNamedDateRange' )
			   DROP PROCEDURE [pal].ctcsp_Get_STCs_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_STCs_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @where varchar(1000)

				SET @sql = 
				  ''SELECT [Id]
				  ,[DocSessionId]
				  ,[EventDateTime] AS StcDateTime
				  ,[EventDuration] AS StcDuration
				  FROM pal.LogEvent ''

				   Set @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''EventDateTime'');

				   IF @where = ''''
					 SET  @Where = ''WHERE (EventName = N''''SyncComplete'''')''
				   ELSE
					 SET @where = @where + '' AND (EventName = N''''SyncComplete'''')''

				EXEC(@sql + @where + '' ORDER BY EventDateTime'');
			END ');

			PRINT 'PAL - Updating ctcsp_Get_CentralFiles_ByNamedDateRange'
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_CentralFiles_ByNamedDateRange' )
			   DROP PROCEDURE [pal].ctcsp_Get_CentralFiles_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_CentralFiles_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				SET NOCOUNT ON;
				DECLARE @sql varchar(2300)
				DECLARE @AndClause varchar(1000)

				SET @sql = 
					''SELECT   
					Data.Id, 
					ProjectId, 
					asset.Project.ProjectNumber AS [Project Number], 
					asset.Project.ProjectName AS [Project Name], 
					asset.Project.ClientName AS [Client Name], 
					UserName AS Contributor, 
					Server, 
					CentralFileName AS [Central File], 
					ShortFileName AS [File Name], 
					LocalFileName AS [Local File], 
					LocalFileSize / 1048576.0 AS [File Size (MB)], 
					RevitVersion AS [Revit Version], 
					IsAudit AS Auditing, 
					DocDateTime AS Opened, 
					STCDateTime AS [Last Saved], 
					LoadTime AS [Open Duration (Sec)], 
					STCDuration AS [STC Duration (Sec)], 
					SessionHours AS [Session Hours], 
					GroupCt AS Groups, 
					InPlaceCt AS [In-place Families], 
					UnPlacedRoomCt AS [Unplaced Rooms], 
					UnenclosedRoomCt AS [Unenclosed Rooms], 
					PlacedRoomCt AS Rooms, 
					UnPlacedSpaceCt AS [Unplaced Spaces], 
					UnenclosedSpaceCt AS [Unenclosed Spaces], 
					PlacedSpaceCt AS Spaces, 
					ViewCt AS Views, 
					PhaseCt AS Phases, 
					DesOptCt AS [Design Options], 
					WorksetCt AS Worksets, 
					FamilyCt AS Families, 
					InstanceCt AS [Family Instances], 
					UnplacedFamilyCt AS [Unplaced Families],
					MaterialCt AS Materials, 
					ViewFilterCt AS [View Filters], 
					LevelCt AS Levels, ElemAddedCt AS Added, 
					ElemDeletedCt AS Deleted, 
					ElemModifiedCt AS Modified, 
					ElemAddedCt + ElemDeletedCt + ElemModifiedCt AS [Edited Items], 
					WarningCt AS Warnings, 
					MachineName,
					LocalTimeOffset,
					BasePoint,
					SurveyPoint,
					AngleToTrueNorth,
					CONVERT(DateTime,CONVERT(Date, DocDateTime, 101)) AS DayOpened 

					FROM (pal.LogDocSession AS Data INNER JOIN asset.Project ON ProjectId = asset.Project.Id) 
					WHERE ([DocDateTime] =
						(SELECT MAX([DocDateTime]) AS Expr1
							FROM     pal.LogDocSession AS LogDocSession_1
								WHERE ([CentralFileName] = Data.[CentralFileName]) AND (ProjectId = Data.ProjectId) AND (STCDuration > 0)) ''
				

				  SET @AndClause = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''DocDateTime'');
				  EXEC (@sql + @AndClause  + '' AND (ProjectId <> ''''00000000-0000-0000-0000-000000000000'''') );'');
			  
				END ');

				
				
			PRINT 'PAL - Updating ctcsp_Get_Current_Links_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Current_Links_ByNamedDateRange' )
			DROP PROCEDURE [pal].ctcsp_Get_Current_Links_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Current_Links_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
			
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @and varchar(1000)

				SET @sql = 
					''SELECT 
						pal.LogLink.DocSessionId, 
						ProjectId, 
						CentralFileName AS [Central File], 
						ShortFileName AS [File Name], 
						pal.LogLink.LinkPath AS [Link Path], 
						pal.LogLink.LinkShortFileName AS [Link Filename], 
						pal.LogLink.LinkType AS [Link Type], 
						pal.LogLink.LinkStatus AS [Link Status], 
						pal.LogLink.UserName, 
						pal.LogLink.LinksDateTime
						FROM pal.LogDocSession AS Data INNER JOIN
						pal.LogLink ON Data.Id = pal.LogLink.DocSessionId

						WHERE ([DocDateTime] =
								(SELECT MAX([DocDateTime]) AS Expr1
									FROM  pal.LogDocSession AS LogDocSession_1
										WHERE ([CentralFileName] = Data.[CentralFileName]) 
										AND (ProjectId = Data.ProjectId) 
										AND (ProjectId <> ''''00000000-0000-0000-0000-000000000000'''')
										AND (STCDuration > 0)
									)
								) ''

				  Set @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''DocDateTime'');

				  EXEC(@sql + @and + '' Order by LinksDateTime'');

			END ');

				
				
			PRINT 'PAL - Updating ctcsp_Get_Current_Machines'
		
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Current_Machines' )
			   DROP PROCEDURE [pal].ctcsp_Get_Current_Machines
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Current_Machines]
			AS
			BEGIN
			
			SET NOCOUNT ON;
		
			DECLARE @sql varchar(1000)

			SET @sql = 
			  ''SELECT        
					DocSessionId, 
					MachineName, 
					IPAddress, 
					OperatingSystem, 
					CPU, 
					RAM, 
					RAM_Slots, 
					Video, 
					HDD, 
					MAC, 
					LogDateTime AS [Date Created]
				FROM pal.LogMachine AS Data
				WHERE (LogDateTime = 
					(SELECT MAX(LogDateTime) AS Expr1
						FROM pal.LogMachine
							WHERE (MachineName = Data.MachineName))) 
				ORDER BY MachineName''

			  EXEC(@sql);

			END ');

				
				
			PRINT 'PAL - Updating ctcsp_Get_Current_Machines_ByNamedDateRange'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Current_Machines_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_Current_Machines_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Current_Machines_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @and varchar(1000)

				SET @sql = 
				  ''SELECT        
						DocSessionId, 
						MachineName, 
						IPAddress, 
						OperatingSystem, 
						CPU, 
						RAM, 
						RAM_Slots, 
						Video, 
						HDD, 
						MAC, 
						LogDateTime AS [Date Created]
					FROM pal.LogMachine AS Data
					WHERE (LogDateTime = 
						(SELECT MAX(LogDateTime) AS Expr1
							FROM pal.LogMachine
								WHERE (MachineName = Data.MachineName))) ''

				  SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''LogDateTime'');

				  EXEC(@sql + @and + '' Order by MachineName'');

				END ');

				
				
			PRINT 'PAL - Updating ctcsp_Get_Current_Views_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Current_Views_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_Current_Views_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Current_Views_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @and varchar(1000)

				SET @sql = 
					''SELECT        
						pal.LogViewType.DocSessionId, 
						ProjectId, 
						CentralFileName AS [Central File], 
						ShortFileName AS [File Name],  
						pal.LogViewType.ViewTypeName AS [View Types], 
						pal.LogViewType.ViewCt AS Views, 
						pal.LogViewType.ViewDateTime AS [Date Created]
						FROM pal.LogDocSession AS Data
						INNER JOIN pal.LogViewType ON Data.Id = pal.LogViewType.DocSessionId
						WHERE ([DocDateTime] =
							(SELECT MAX([DocDateTime]) AS Expr1
								FROM pal.LogDocSession AS LogDocSession_1
									WHERE ([CentralFileName] = Data.[CentralFileName]) AND (ProjectId = Data.ProjectId) 
									AND (ProjectId <> ''''00000000-0000-0000-0000-000000000000'''') 
									AND (STCDuration > 0) 
							)) ''

				  SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');
				  EXEC(@sql + @and + '' ORDER BY [Date Created]'');

				END ');

				
				
			PRINT 'PAL - Updating ctcsp_Get_Current_Warnings_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Current_Warnings_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_Current_Warnings_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Current_Warnings_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
			
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @and varchar(1000)

				SET @sql = 
				  ''SELECT
						pal.LogWarning.DocSessionId, 
						ProjectId, 
						CentralFileName AS [Central File], 
						ShortFileName AS [File Name],
						pal.LogWarning.WarningDateTime AS [Date Created], 
						pal.LogWarning.WarningId, pal.LogWarnings.Severity, 
						pal.LogWarning.Description, 
						pal.LogWarning.ElementId, 
						pal.LogWarning.ElementName, 
						pal.LogWarning.LevelName AS [Level Name], 
						pal.LogWarning.Workset
					FROM pal.LogDocSession AS Data
					INNER JOIN pal.LogWarning ON Data.Id = pal.LogWarning.DocSessionId
					WHERE ([DocDateTime] =
								(SELECT MAX([DocDateTime]) AS Expr1
									FROM pal.LogDocSession AS LogDocSession_1
										WHERE (([CentralFileName] = Data.[CentralFileName]) 
										AND (ProjectId = Data.ProjectId) 
										AND (ProjectId <> ''''00000000-0000-0000-0000-000000000000'''')
										AND (STCDuration > 0)
										)
								)
						  ) ''

				  SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');
				
				  EXEC(@sql + @and +  '' ORDER BY [Date Created]'');

				END ');

				
			PRINT 'PAL - Updating ctcsp_Get_LogChanges_ByNamedDateRange'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogChanges_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_LogChanges_ByNamedDateRange

				
			PRINT 'PAL - Updating ctcsp_Get_LogDocSessions_ByNamedDateRange'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessions_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_LogDocSessions_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessions_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @where varchar(1000)

				SET @sql = 
				  ''SELECT [Id]
				  ,[ProjectId]
				  ,[UserName]
				  ,[Server]
				  ,[CentralFileName]
				  ,[ShortFileName]
				  ,[LocalFileName]
				  ,[LocalFileSize]
				  ,[RevitVersion]
				  ,[IsAudit]
				  ,[DocDateTime]
				  ,[LoadTime]
				  ,[STCDuration]
				  ,[STCDateTime]
				  ,[SessionHours]
				  ,[PhaseCt]
				  ,[DesOptCt]
				  ,[WorksetCt]
				  ,[ViewCt]
				  ,[GroupCt]
				  ,[FamilyCt]
				  ,[InstanceCt]
				  ,[UnplacedFamilyCt]
				  ,[InPlaceCt]
				  ,[UnPlacedRoomCt]
				  ,[UnenclosedRoomCt]
				  ,[PlacedRoomCt]
				  ,[UnPlacedSpaceCt]
				  ,[UnenclosedSpaceCt]
				  ,[PlacedSpaceCt]
				  ,[MaterialCt]
				  ,[ViewFilterCt]
				  ,[LevelCt]
				  ,[ElemAddedCt]
				  ,[ElemDeletedCt]
				  ,[ElemModifiedCt]
				  ,[WarningCt]
				  ,[HasClosed]
				  ,[MachineName]
				  ,[LocalTimeOffset]
				  ,[BasePoint]
				  ,[SurveyPoint]
				  ,[AngleToTrueNorth]
				  FROM pal.LogDocSession ''

				  SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''DocDateTime'');

				  EXEC(@sql + @where  + '' ORDER BY DocDateTime'');

			END ');


			
			PRINT 'PAL - Updating ctcsp_Get_LogEvents_ByNamedDateRange'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogEvents_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_LogEvents_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogEvents_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
			
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @where varchar(1000)

				SET @sql = 
				''SELECT [Id]
				  ,[DocSessionId]
				  ,[EventId]
				  ,[EventType]
				  ,[EventName]
				  ,[ViewName]
				  ,[OpenViewCt]
				  ,[EventDateTime]
				  ,[EventDuration]
				  FROM pal.LogEvent ''

				  SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''EventDateTime'');

				  EXEC(@sql + @where  + '' ORDER BY EventDateTime'');
			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_LogLinks_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogLinks_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_LogLinks_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogLinks_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @where varchar(1000)

				SET @sql = 
					''SELECT [Id]
					,[DocSessionId]
					,[LinkPath]
					,[LinkShortFileName]
					,[LinkType]
					,[LinkStatus]
					,[UserName]
					,[LinksDateTime]
					,[CheckVal]
					FROM pal.LogLink ''

				  SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''LinksDateTime'');

				  EXEC(@sql + @where  + '' ORDER BY LinksDateTime'');

			END');

			
			
			PRINT 'PAL - Updating ctcsp_Get_LogMachines_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogMachines_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_LogMachines_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogMachines_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
				AS
				BEGIN
					SET NOCOUNT ON;
			
					DECLARE @sql varchar(1000)
					DECLARE @where varchar(1000)

					SET @sql = 
						''SELECT [Id]
						,[DocSessionId]
						,[ProcessorId]
						,[MachineName]
						,[MAC]
						,[OperatingSystem]
						,[HDD]
						,[Motherboard]
						,[Bios]
						,[RAM]
						,[RAM_Slots]
						,[CPU]
						,[Video]
						,[LogDateTime]
						,[IPAddress]
						FROM pal.LogMachine ''

					  SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''LogDateTime'');

					  EXEC(@sql + @where  + '' ORDER BY LogDateTime'');

				END ');

				
				
			PRINT 'PAL - Updating ctcsp_Get_LogSummaries_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogSummaries_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_LogSummaries_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogSummaries_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @where varchar(1000)

				SET @sql = 
					''SELECT [Id]
					,[DocSessionId]
					,[EventId]
					,[GroupCt]
					,[InPlaceCt]
					,[UnPlacedRoomCt]
					,[UnenclosedRoomCt]
					,[PlacedRoomCt]
					,[ViewCt]
					,[PhaseCt]
					,[DesOptCt]
					,[WorksetCt]
					,[FamilyCt]
					,[InstanceCt]
					,[MaterialCt]
					,[ViewFilterCt]
					,[SummaryDateTime]
					,[UnplacedFamilyCt]
					,[LevelCt]
					FROM pal.LogSummary ''

				  SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''SummaryDateTime'');

				  EXEC(@sql + @where  + '' ORDER BY SummaryDateTime'');

				END ');

				
				
			PRINT 'PAL - Updating ctcsp_Get_LogViewTypes_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogViewTypes_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_LogViewTypes_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogViewTypes_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @where varchar(1000)

				SET @sql = 
					''SELECT [Id]
					,[DocSessionId]
					,[ViewTypeName]
					,[ViewCt]
					,[ViewDateTime]
					,[CheckVal]
					FROM pal.LogViewType ''

				  SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''ViewDateTime'');

				  EXEC(@sql + @where  + '' ORDER BY ViewDateTime'');

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_LogWarnings_ByNamedDateRange'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogWarnings_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_LogWarnings_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogWarnings_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @where varchar(1000)

				SET @sql = 
					''SELECT [Id]
					,[DocSessionId]
					,[Severity]
					,[Description]
					,[ElementId]
					,[ElementName]
					,[LevelName]
					,[Workset]
					,[WarningDateTime]
					,[CheckVal]
					,[WarningId]
					FROM pal.LogWarning ''

				  Set @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''WarningDateTime'');

				  EXEC(@sql + @where  + '' ORDER BY WarningDateTime'');

			END ');

				
				
			PRINT 'PAL - Updating ctcsp_Get_Session_Links_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Session_Links_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_Session_Links_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Session_Links_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				-- SET NOCOUNT ON is added to prevent extra result sets from
				-- interfering with SELECT statements.
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @and varchar(1000)

				SET @sql = 
				  ''SELECT        
						Data.Id AS DocSessionId, 
						[STCDateTime] AS [Date Created], 
						pal.LogLink.LinkPath AS [Link Path], 
						pal.LogLink.LinkShortFileName AS [Link Filename], 
						pal.LogLink.LinkType AS [Link Type], 
						pal.LogLink.LinkStatus AS [Link Status]
					FROM pal.LogDocSession AS Data 
					INNER JOIN pal.LogLink ON Data.Id = pal.LogLink.DocSessionId
					WHERE ([STCDateTime] =
						(SELECT MAX([STCDateTime]) AS Expr1
							FROM pal.LogDocSession AS ctcvw_Sessions_1
								WHERE ((Id = Data.Id) 
								AND (ProjectId <> ''''00000000-0000-0000-0000-000000000000'''') 
								AND (STCDuration > 0))
							)
						) ''

				  SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[STCDateTime]'');

				  EXEC(@sql + @and + '' ORDER BY [Date Created]'');

				END ' );
				
				
			PRINT 'PAL - Updating ctcsp_Get_Session_Machines_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Session_Machines_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_Session_Machines_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Session_Machines_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN

				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @and varchar(1000)

				SET @sql = 
				  ''SELECT        
						pal.LogMachine.DocSessionId, 
						pal.LogMachine.MachineName, 
						pal.LogMachine.IPAddress, 
						pal.LogMachine.OperatingSystem, 
						pal.LogMachine.CPU, 
						pal.LogMachine.RAM, 
						pal.LogMachine.RAM_Slots, 
						pal.LogMachine.Video, 
						pal.LogMachine.HDD, 
						pal.LogMachine.MAC, 
						pal.LogMachine.LogDateTime AS [Date Created]
					FROM pal.LogDocSession 
					INNER JOIN pal.LogMachine ON pal.LogDocSession.Id = pal.LogMachine.DocSessionId
					WHERE ((pal.LogDocSession.ProjectId <> ''''00000000-0000-0000-0000-000000000000'''')
					AND (STCDuration > 0)) ''

				SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');	
			
				EXEC(@sql + @and + '' ORDER BY [Date Created]'');

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_Session_Views_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Session_Views_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_Session_Views_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Session_Views_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				-- SET NOCOUNT ON is added to prevent extra result sets from
				-- interfering with SELECT statements.
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @and varchar(1000)

				SET @sql = 
				  ''SELECT        
					Data.Id AS DocSessionId, 
					Data.[STCDateTime] AS [Date Created], 
					pal.LogViewType.ViewTypeName AS [View Types], 
					pal.LogViewType.ViewCt AS Views
					FROM pal.LogDocSession AS Data 
					INNER JOIN pal.LogViewType ON Data.Id = pal.LogViewType.DocSessionId
					WHERE (Data.[STCDateTime] =
							(SELECT MAX([STCDateTime]) AS Expr1
								FROM pal.LogDocSession AS ctcvw_Sessions_1
								WHERE   ((Id = Data.Id)
								AND (ProjectId <> ''''00000000-0000-0000-0000-000000000000'''')
								AND (STCDuration > 0))
							)
						) ''

				  Set @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');
				
				  EXEC(@sql + @and + '' ORDER BY [Date Created]'');

			END ');
				
				
				
			PRINT 'PAL - Updating ctcsp_Get_Session_Warnings_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Session_Warnings_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_Session_Warnings_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Session_Warnings_ByNamedDateRange]
			(
				@p_NamedDateRange nvarchar(7)
			)
			AS
			BEGIN
				
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1000)
				DECLARE @and varchar(1000)

				SET @sql = 
				  ''SELECT 
					pal.LogWarning.DocSessionId, 
					pal.LogWarning.Severity, 
					pal.LogWarning.Description, 
					pal.LogWarning.ElementId, 
					pal.LogWarning.ElementName, 
					pal.LogWarning.LevelName AS [Level Name], 
					pal.LogWarning.Workset, 
					pal.LogWarning.WarningDateTime AS [Date Created]
					FROM pal.LogDocSession As Data
					INNER JOIN pal.LogWarning ON Data.Id = pal.LogWarning.DocSessionId
					WHERE (Data.[STCDateTime] =
								(SELECT MAX([STCDateTime]) AS Expr1
									FROM pal.LogDocSession AS ctcvw_Sessions_1
									WHERE   ((Id = Data.Id)
									AND (ProjectId <> ''''00000000-0000-0000-0000-000000000000'''')
									AND (STCDuration > 0))
								)
							)  ''

				  SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');
				  EXEC(@sql + @and + '' ORDER BY [Date Created]'');

			END ');

			
			
			PRINT 'PAL - Updating ctcsp_Get_Sessions_ByNamedDateRange'
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Sessions_ByNamedDateRange' )
				DROP PROCEDURE [pal].ctcsp_Get_Sessions_ByNamedDateRange
			EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Sessions_ByNamedDateRange]
				@p_NamedDateRange nvarchar(7)
			AS
			BEGIN
				-- SET NOCOUNT ON is added to prevent extra result sets from
				-- interfering with SELECT statements.
				SET NOCOUNT ON;
			
				DECLARE @sql varchar(1600)
				DECLARE @where varchar(1000)

				SET @sql = 
				  ''SELECT        
					LogDocSession.Id, 
					ProjectId, 
					Project.ProjectNumber AS [Project Number], 
					Project.ProjectName AS [Project Name], 
					Project.ClientName AS [Client Name], 
					UserName AS Contributor, 
					Server, 
					CentralFileName AS [Central File], 
					ShortFileName AS [File Name], 
					LocalFileName AS [Local File], 
					LocalFileSize / 1048576.0 AS [File Size (MB)], 
					RevitVersion AS [Revit Version], 
					IsAudit AS Auditing, 
					DocDateTime AS Opened, 
					STCDateTime AS [Last Saved], 
					LoadTime AS [Open Duration (Sec)], 
					STCDuration AS [STC Duration (Sec)], 
					SessionHours AS [Session Hours], 
					GroupCt AS Groups, 
					InPlaceCt AS [In-place Families], 
					UnPlacedRoomCt AS [Unplaced Rooms], 
					UnenclosedRoomCt AS [Unenclosed Rooms], 
					PlacedRoomCt AS Rooms, 
					UnPlacedSpaceCt AS [Unplaced Spaces], 
					UnenclosedSpaceCt AS [Unenclosed Spaces], 
					PlacedSpaceCt AS Spaces,
					ViewCt AS Views, 
					PhaseCt AS Phases, 
					DesOptCt AS [Design Options], 
					WorksetCt AS Worksets, 
					FamilyCt AS Families, 
					InstanceCt AS [Family Instances], 
					UnplacedFamilyCt AS [Unplaced Families],
					MaterialCt AS Materials, 
					ViewFilterCt AS [View Filters], 
					LevelCt AS Levels, ElemAddedCt AS Added, 
					ElemDeletedCt AS Deleted, 
					ElemModifiedCt AS Modified, 
					ElemAddedCt + ElemDeletedCt + 
					ElemModifiedCt AS [Edited Items], 
					WarningCt AS Warnings,
					HasClosed As [Session Closed], 
					MachineName,
					LocalTimeOffset,
					BasePoint,
					SurveyPoint,
					AngleToTrueNorth,
					CONVERT(DateTime,CONVERT(Date, DocDateTime, 101)) AS DayOpened,
					[Last Action]
					FROM pal.LogDocSession INNER JOIN asset.Project ON ProjectId = asset.Project.Id ''
				
				  SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''DocDateTime'');
				  EXEC(@sql + @where + '' AND (ProjectId <> ''''00000000-0000-0000-0000-000000000000'''') AND (STCDuration > 0);'');
			END ');
			
		
		
			PRINT 'End PAL PowerBI stored procedures'	
		
		
		
		
			
			
			---------------------------------------------------------------------------------------------------------------------------------------------
			-- MUST UPDATE THE PAL VIEWS TO USE THE NEW PAL SCHEMA
			---------------------------------------------------------------------------------------------------------------------------------------------

			PRINT 'PAL - Updating PAL Views'
			PRINT ''
			PRINT 'PAL - Updating ctcvw_Projects'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Projects' )
					DROP VIEW  pal.ctcvw_Projects
				EXEC('CREATE VIEW [pal].[ctcvw_Projects]
				AS
				SELECT  TOP 100 PERCENT
						Id, 
						ProjectNumber + N'' - '' + ProjectName AS Project, 
						ProjectNumber AS [Project Number], 
						ProjectName AS [Project Name], 
						ClientName AS [Client Name], 
						ProjectIssueDate AS [Issue Date], 
						DATEDIFF(DAY, { fn NOW() }, ProjectIssueDate) AS [Days Until Issue]
						,[Office]
						,[ProjectStatus]
						,[ClientName]
						,[OrgDescription]
						,[OrgName]
						,[Author]
						,[BuildingName]
						,[StreetAddress]
						,[StreetAddress2]
						,[StreetAddress3]
						,[City]
						,[StateOrProvince]
						,[PostalCode]
						,[CountryName]
		--				,[CreatedBy]
						,[DateCreated]
						,[LastUpdated]
						,[CompanyID]
				FROM    asset.Project
				WHERE   (Id <> ''00000000-0000-0000-0000-000000000000'')
				ORDER BY [Issue Date] ')
			PRINT 'PAL - Updating ctcvw_Sessions_LastSTC'	
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Sessions_LastSTC' )
					DROP VIEW  pal.ctcvw_Sessions_LastSTC
				EXEC('CREATE VIEW [pal].[ctcvw_Sessions_LastSTC]
				AS
				SELECT  DocSessionId,  
						EventId, 
						EventDuration, 
						EventDateTime
				FROM    pal.LogEvent as Data
				WHERE  (EventDateTime =
							(SELECT MAX(EventDateTime) AS Expr1
								FROM pal.LogEvent
									WHERE (EventName = N''SyncComplete'')
									AND (DocSessionId = Data.DocSessionId))) ')

			PRINT 'PAL - Updating ctcvw_Sessions_LastEvent'	
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Sessions_LastEvent' )
					DROP VIEW  pal.ctcvw_Sessions_LastEvent
				EXEC('CREATE VIEW [pal].[ctcvw_Sessions_LastEvent]
				AS
				SELECT  DocSessionId, 
						MAX(EventDateTime) AS EventDateTime
				FROM    pal.LogEvent
				GROUP BY DocSessionId ')
				
			PRINT 'PAL - Updating ctcvw_Sessions_LastSummary'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Sessions_LastSummary' )
				DROP VIEW  pal.ctcvw_Sessions_LastSummary
				EXEC('CREATE VIEW [pal].[ctcvw_Sessions_LastSummary]
				AS
				SELECT  DocSessionId, 
						EventId, 
						GroupCt, 
						InPlaceCt, 
						UnPlacedRoomCt, 
						UnenclosedRoomCt, 
						PlacedRoomCt, 
						UnPlacedSpaceCt, 
						UnenclosedSpaceCt,
						PlacedSpaceCt, 
						ViewCt, 
						PhaseCt, 
						DesOptCt, 
						WorksetCt, 
						FamilyCt, 
						InstanceCt, 
						UnplacedFamilyCt, 
						MaterialCt, 
						ViewFilterCt, 
						SummaryDateTime, 
						LevelCt
				FROM    pal.LogSummary AS Data
				WHERE  (SummaryDateTime =
						(SELECT MAX(SummaryDateTime) AS Expr1
						 FROM pal.LogSummary
						 WHERE (DocSessionId = Data.DocSessionId))) ')

			PRINT 'PAL - Updating ctcvw_Warnings_Total'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Warnings_Total' )
				DROP VIEW  pal.ctcvw_Warnings_Total
				EXEC('CREATE VIEW [pal].[ctcvw_Warnings_Total]
				AS
				SELECT   DocSessionId, 
						 COUNT(ElementId) AS Warnings
				FROM     pal.LogWarning
				GROUP BY DocSessionId ')

			PRINT 'PAL - Updating ctcvw_Sessions'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Sessions' )
				DROP VIEW  pal.ctcvw_Sessions
				EXEC('CREATE VIEW [pal].[ctcvw_Sessions]
				AS
				SELECT  Data.Id, 
						Data.CompanyID, 
						Data.ProjectId, 
						Project.ProjectNumber AS [Project Number], 
						Project.ProjectName AS [Project Name], 
						Project.ClientName AS [Client Name], 
						Data.UserName AS Contributor, 
						Data.MachineName, 
						Data.Server, 
						Data.CentralFileName AS [Central File], 
						Data.ShortFileName AS [File Name], 
						Data.LocalFileName AS [Local File], 
						Data.LocalFileSize / 1048576.0 AS [File Size (MB)], 
						Data.RevitVersion AS [Revit Version], 
						Data.IsAudit AS Auditing, 
						Data.DocDateTime AS Opened, 
						Data.LocalTimeOffset,
						Data.STCDateTime AS [Last Saved], 
						Data.LoadTime AS [Open Duration (Sec)], 
						Data.STCDuration AS [STC Duration (Sec)], 
						Data.SessionHours AS [Session Hours], 
						Data.GroupCt AS Groups, 
						Data.InPlaceCt AS [In-place Families], 
						Data.UnPlacedRoomCt AS [Unplaced Rooms], 
						Data.UnenclosedRoomCt AS [Unenclosed Rooms], 
						Data.PlacedRoomCt AS Rooms, 
						Data.UnPlacedSpaceCt AS [Unplaced Spaces], 
						Data.UnenclosedSpaceCt As [Unenclosed Spaces], 
						Data.PlacedSpaceCt As Spaces,
						Data.ViewCt AS Views, 
						Data.PhaseCt AS Phases, 
						Data.DesOptCt AS [Design Options], 
						Data.WorksetCt AS Worksets, 
						Data.FamilyCt AS Families, 
						Data.InstanceCt AS [Family Instances], 
						Data.UnplacedFamilyCt AS [Unplaced Families], 
						Data.MaterialCt AS Materials, 
						Data.ViewFilterCt AS [View Filters], 
						Data.LevelCt AS Levels, 
						Data.ElemAddedCt AS Added, 
						Data.ElemDeletedCt AS Deleted, 
						Data.ElemModifiedCt AS Modified, 
						ISNULL(Data.ElemAddedCt + Data.ElemDeletedCt + Data.ElemModifiedCt, 0) 
										 AS [Edited Items], 
						Data.WarningCt AS Warnings, 
						CONVERT(DateTime, CONVERT(Date, Data.DocDateTime, 101)) AS DayOpened, 
						Data.HasClosed,
						Data.BasePoint,
						Data.SurveyPoint,
						Data.AngleToTrueNorth,
						pal.ctcvw_Sessions_LastEvent.EventDateTime AS [Last Action]
					FROM pal.LogDocSession AS Data 
					INNER JOIN asset.Project ON Data.ProjectId = asset.Project.Id 
					INNER JOIN pal.ctcvw_Sessions_LastEvent ON Data.Id = pal.ctcvw_Sessions_LastEvent.DocSessionId
					WHERE (Data.ProjectId <> ''00000000-0000-0000-0000-000000000000'') ')

			PRINT 'PAL - Updating ctcvw_CentralFiles'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_CentralFiles' )
				DROP VIEW  pal.ctcvw_CentralFiles
				EXEC('CREATE VIEW [pal].[ctcvw_CentralFiles]
				AS
				SELECT  Id, 
						ProjectId, 
						[Project Number], 
						[Project Name], 
						[Client Name], 
						Contributor, 
						Server, 
						[Central File], 
						[File Name], 
						[Local File], 
						[File Size (MB)], 
						[Revit Version], 
						Auditing, 
						Opened, 
						LocalTimeOffset,
						[Last Saved], 
						[Open Duration (Sec)], 
						[STC Duration (Sec)], 
						[Session Hours], 
						Groups, 
						[In-place Families], 
						[Unplaced Rooms], 
						[Unenclosed Rooms], 
						Rooms,
						[Unplaced Spaces], 
						[Unenclosed Spaces], 
						Spaces, 
						Views, 
						Phases, 
						[Design Options], 
						Worksets, 
						Families, 
						[Family Instances], 
						[Unplaced Families], 
						Materials, 
						[View Filters], 
						Warnings, 
						Levels,
						BasePoint,
						SurveyPoint,
						AngleToTrueNorth
				FROM    ctcvw_Sessions AS Data
				WHERE   ([Last Saved] = (SELECT MAX([Last Saved]) AS Expr1
											FROM    ctcvw_Sessions AS ctcvw_Sessions_1
											   WHERE ([Central File] = Data.[Central File]) 
											   AND (ProjectId = Data.ProjectId))) ')

			PRINT 'PAL - Updating ctcvw_CentralFiles_All'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_CentralFiles_All' )
					DROP VIEW  pal.ctcvw_CentralFiles_All
				EXEC('CREATE VIEW [pal].[ctcvw_CentralFiles_All]
				AS
				SELECT  Id, 
						ProjectId, 
						[Project Number], 
						[Project Name], 
						[Client Name], 
						Contributor, 
						Server, 
						[Central File], 
						[File Name], 
						[Local File], 
						[File Size (MB)], 
						[Revit Version], 
						Auditing, 
						Opened, 
						LocalTimeOffset,
						[Last Saved], 
						[Open Duration (Sec)], 
						[STC Duration (Sec)], 
						[Session Hours], 
						Groups, 
						[In-place Families], 
						[Unplaced Rooms], 
						[Unenclosed Rooms], 
						Rooms,
						[Unplaced Spaces], 
						[Unenclosed Spaces], 
						Spaces, 
						Views, 
						Phases, 
						[Design Options], 
						Worksets, 
						Families, 
						[Family Instances], 
						[Unplaced Families], 
						Materials, 
						[View Filters], 
						Warnings, 
						Levels,
						BasePoint,
						SurveyPoint,
						AngleToTrueNorth
				FROM    ctcvw_Sessions AS Data
				WHERE   (Opened =
							(SELECT MAX(Opened) AS Expr1
							 FROM ctcvw_Sessions
							 WHERE  ([Central File] = Data.[Central File]) 
								AND (ProjectId = Data.ProjectId) 
								AND (DayOpened = Data.DayOpened))) ')

			PRINT 'PAL - Updating ctcvw_CentralFiles_Current'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_CentralFiles_Current' )
					DROP VIEW  pal.ctcvw_CentralFiles_Current
				EXEC('CREATE VIEW [pal].[ctcvw_CentralFiles_Current]
				AS
				SELECT  Id, 
						ProjectId, 
						[Project Number], 
						[Project Name], 
						[Client Name], 
						Contributor, 
						Server, 
						[Central File], 
						[File Name], 
						[Local File], 
						[File Size (MB)], 
						[Revit Version], 
						Auditing, 
						Opened, 
						LocalTimeOffset,
						[Last Saved], 
						[Open Duration (Sec)], 
						[STC Duration (Sec)], 
						[Session Hours], 
						Groups, 
						[In-place Families], 
						[Unplaced Rooms], 
						[Unenclosed Rooms], 
						Rooms,
						[Unplaced Spaces], 
						[Unenclosed Spaces], 
						Spaces, 
						Views, 
						Phases, 
						[Design Options], 
						Worksets, 
						Families, 
						[Family Instances], 
						[Unplaced Families], 
						Materials, 
						[View Filters], 
						Warnings, 
						Levels,
						BasePoint,
						SurveyPoint,
						AngleToTrueNorth
				FROM    ctcvw_Sessions AS Data
				WHERE   ([Last Saved] =
						(SELECT MAX([Last Saved]) AS Expr1
							FROM ctcvw_Sessions AS ctcvw_Sessions_1
							 WHERE  ([Central File] = Data.[Central File]) 
							 AND (ProjectId = Data.ProjectId))) ')

			PRINT 'PAL - Updating ctcvw_FileSizes'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_FileSizes' )
					DROP VIEW  pal.ctcvw_FileSizes
				EXEC('CREATE VIEW [pal].[ctcvw_FileSizes]
				AS
				SELECT  ProjectId, 
						[Central File], 
						[File Name], 
						[File Size (MB)], 
						Opened
				FROM    ctcvw_Sessions AS Data
				WHERE   (Opened = (SELECT   MAX(Opened) AS Expr1
							FROM ctcvw_Sessions
							WHERE   ([Central File] = Data.[Central File]) 
							AND (ProjectId = Data.ProjectId))) ')

			PRINT 'PAL - Updating ctcvw_Links_All'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Links_All' )
				DROP VIEW  pal.ctcvw_Links_All
				EXEC('CREATE VIEW [pal].[ctcvw_Links_All]
				AS
				SELECT  Data.Id AS DocSessionId, 
						Data.[Last Saved] AS [Date Created], 
						LogLink.LinkPath AS [Link Path], 
						LogLink.LinkShortFileName AS [Link Filename], 
						LogLink.LinkType AS [Link Type], 
						LogLink.LinkStatus AS [Link Status]
				FROM    ctcvw_Sessions AS Data 
					INNER JOIN pal.LogLink ON Data.Id = LogLink.DocSessionId
				WHERE (Data.[Last Saved] =
								(SELECT MAX([Last Saved]) AS Expr1
								 FROM ctcvw_Sessions AS ctcvw_Sessions_1
								 WHERE (Id = Data.Id))) ')

			PRINT 'PAL - Updating ctcvw_Links_Current'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Links_Current' )
					DROP VIEW  pal.ctcvw_Links_Current
				EXEC('CREATE VIEW [pal].[ctcvw_Links_Current]
				AS
				SELECT  LogLink.DocSessionId, 
						ctcvw_CentralFiles.ProjectId, 
						ctcvw_CentralFiles.[Central File], 
						ctcvw_CentralFiles.[File Name], 
						LogLink.LinkPath AS [Link Path], 
						LogLink.LinkShortFileName AS [Link Filename], 
						LogLink.LinkType AS [Link Type], 
						LogLink.LinkStatus AS [Link Status], 
						LogLink.UserName, 
						LogLink.LinksDateTime
				FROM    ctcvw_CentralFiles 
					INNER JOIN pal.LogLink ON ctcvw_CentralFiles.Id = LogLink.DocSessionId ')

			PRINT 'PAL - Updating ctcvw_Machines_All'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Machines_All' )
				DROP VIEW  pal.ctcvw_Machines_All
				EXEC('CREATE VIEW [pal].[ctcvw_Machines_All]
				AS
				SELECT  LogMachine.DocSessionId, 
						LogMachine.MachineName, 
						LogMachine.IPAddress, 
						LogMachine.OperatingSystem, 
						LogMachine.CPU, 
						LogMachine.RAM, 
						LogMachine.RAM_Slots, 
						LogMachine.Video, 
						LogMachine.HDD, 
						LogMachine.MAC, 
						LogMachine.LogDateTime AS [Date Created]
				FROM    ctcvw_Sessions 
					INNER JOIN pal.LogMachine 
					ON ctcvw_Sessions.Id = LogMachine.DocSessionId ')

			PRINT 'PAL - Updating ctcvw_Machines_Current'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Machines_Current' )
				DROP VIEW  pal.ctcvw_Machines_Current
				EXEC('CREATE VIEW [pal].[ctcvw_Machines_Current]
				AS
				SELECT  DocSessionId, 
						MachineName, 
						IPAddress, 
						OperatingSystem, 
						CPU, 
						RAM, 
						RAM_Slots, 
						Video, 
						HDD, 
						MAC, 
						LogDateTime AS [Date Created]
				FROM    pal.LogMachine AS Data
				WHERE   (LogDateTime =
							 (SELECT MAX(LogDateTime) AS Expr1
							  FROM pal.LogMachine
							  WHERE (MachineName = Data.MachineName))) ')

			PRINT 'PAL - Updating ctcvw_Views_All'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Views_All' )
					DROP VIEW  pal.ctcvw_Views_All
				EXEC('CREATE VIEW [pal].[ctcvw_Views_All]
				AS
				SELECT  Data.Id AS DocSessionId, 
						Data.[Last Saved] AS [Date Created], 
						LogViewType.ViewTypeName AS [View Types], 
						LogViewType.ViewCt AS Views
				FROM    ctcvw_Sessions AS Data 
					INNER JOIN  pal.LogViewType 
					ON Data.Id = LogViewType.DocSessionId
				WHERE (Data.[Last Saved] =
						(SELECT MAX([Last Saved]) AS Expr1
							FROM ctcvw_Sessions AS ctcvw_Sessions_1
							WHERE (Id = Data.Id))) ')

			PRINT 'PAL - Updating ctcvw_Views_Current'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Views_Current' )
					DROP VIEW  pal.ctcvw_Views_Current
				EXEC('CREATE VIEW [pal].[ctcvw_Views_Current]
				AS
				SELECT  LogViewType.DocSessionId, 
						ctcvw_CentralFiles.ProjectId, 
						ctcvw_CentralFiles.[Central File], 
						ctcvw_CentralFiles.[File Name], 
						LogViewType.ViewTypeName AS [View Types], 
						LogViewType.ViewCt AS Views, 
						LogViewType.ViewDateTime AS [Date Created]
				FROM    ctcvw_CentralFiles 
					INNER JOIN pal.LogViewType 
					ON ctcvw_CentralFiles.Id = LogViewType.DocSessionId ')

			PRINT 'PAL - Updating ctcvw_Warnings_All'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Warnings_All' )
					DROP VIEW  pal.ctcvw_Warnings_All
				EXEC('CREATE VIEW [pal].[ctcvw_Warnings_All]
				AS
				SELECT  LogWarning.DocSessionId, 
						LogWarning.Severity, 
						LogWarning.Description, 
						LogWarning.ElementId, 
						LogWarning.ElementName, 
						LogWarning.LevelName AS [Level Name], 
						LogWarning.Workset, 
						LogWarning.WarningDateTime AS [Date Created]
				FROM    ctcvw_Sessions 
					INNER JOIN  pal.LogWarning 
					ON ctcvw_Sessions.Id = LogWarning.DocSessionId ')

			PRINT 'PAL - Updating ctcvw_Warnings_Current'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Warnings_Current' )
					DROP VIEW  pal.ctcvw_Warnings_Current
				EXEC('CREATE VIEW [pal].[ctcvw_Warnings_Current]
				AS
				SELECT  LogWarning.DocSessionId, 
						ctcvw_CentralFiles_Current.ProjectId, 
						ctcvw_CentralFiles_Current.[Central File], 
						ctcvw_CentralFiles_Current.[File Name], 
						LogWarning.WarningDateTime AS [Date Created], 
						LogWarning.WarningId, 
						LogWarning.Severity, 
						LogWarning.Description, 
						LogWarning.ElementId, 
						LogWarning.ElementName, 
						LogWarning.LevelName AS [Level Name], 
						LogWarning.Workset
				FROM    ctcvw_CentralFiles_Current 
					INNER JOIN pal.LogWarning 
					ON ctcvw_CentralFiles_Current.Id = LogWarning.DocSessionId ')
			PRINT 'End View creation'
		
		
		END  -- Must update PAL stored procedures and views from schema version 3 to 4
	
	---------------------------------------------------------------------------------------------------------------------------------------------
	---------------------------------------------------------------------------------------------------------------------------------------------
	---------------------------------------------------------------------------------------------------------------------------------------------
	--
	--  GENERAL HELPER FUNCTIONS BEGIN HERE
	--
	---------------------------------------------------------------------------------------------------------------------------------------------
	---------------------------------------------------------------------------------------------------------------------------------------------
	---------------------------------------------------------------------------------------------------------------------------------------------

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp__DeletePrimaryKey')
		DROP PROCEDURE dbo.ctcsp__DeletePrimaryKey

	EXEC('
	CREATE PROCEDURE [dbo].ctcsp__DeletePrimaryKey
	(
		@showLogMessages bit,
		@tableName nvarchar(MAX),
		@tableNameNoSchema NVARCHAR(200),
		@primaryKeyNameFound nvarchar(200) out
	)
	AS
		SET NOCOUNT ON;

		IF @showLogMessages = 1
			BEGIN
				PRINT ''********** BEGIN ctcsp__DeletePrimaryKey''
				PRINT ''@tableName = '' + @tableName
			END

		SET @primaryKeyNameFound = null

		DECLARE @primaryKeyConstraintName nvarchar(MAX)
		SELECT @primaryKeyConstraintName = name 
		FROM sys.key_constraints  
		WHERE type = ''PK'' AND OBJECT_NAME(parent_object_id) = @tableNameNoSchema;  

		IF @showLogMessages = 1
			PRINT ''Primary key constraint name found is '' + @primaryKeyConstraintName
		
		DECLARE @command nvarchar(2048)

		IF (@primaryKeyConstraintName IS NOT NULL AND @primaryKeyConstraintName <> '''')
			BEGIN

				SET @command = ''ALTER TABLE '' + @tableName + '' DROP CONSTRAINT ['' + @primaryKeyConstraintName + '']''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Dropping existing primary key constraint '' + @primaryKeyConstraintName + '' from table '' + @tableName
						PRINT @command
					END

				EXEC(@command)

				SELECT @primaryKeyNameFound = @primaryKeyConstraintName
			END
		ELSE
			BEGIN
				IF @showLogMessages = 1
					PRINT ''No existing primary key found on table '' + @tableName
			END

		IF @showLogMessages = 1
			PRINT ''********** END ctcsp__DeletePrimaryKey''

	')	-- ctcsp__DeletePrimaryKey






	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp__ChangePrimaryKey')
		DROP PROCEDURE dbo.ctcsp__ChangePrimaryKey

	EXEC('
	CREATE PROCEDURE [dbo].ctcsp__ChangePrimaryKey
	(
		@showLogMessages bit,
		@tableName nvarchar(MAX),
		@tableNameNoSchema NVARCHAR(200),
		@newPKFieldNamesCommaDelimited nvarchar(MAX),
		@createAsClustered bit,
		@newPKConstraintNameOverride NVARCHAR(200) = NULL
	)
	AS
		SET NOCOUNT ON;

		IF @showLogMessages = 1
			BEGIN
				PRINT ''********** BEGIN ctcsp__ChangePrimaryKey''
				PRINT ''@tableName = '' + @tableName
				PRINT ''@newPKFieldNamesCommaDelimited = '' + @newPKFieldNamesCommaDelimited
				PRINT ''@newPKConstraintNameOverride = '' + @newPKConstraintNameOverride
			END

		-- Delete the old primary key, if any

		DECLARE @primaryKeyConstraintName nvarchar(MAX) = NULL
		EXEC ctcsp__DeletePrimaryKey 1, @tableName, @tableNameNoSchema, @primaryKeyConstraintName OUTPUT

		DECLARE @command nvarchar(2048)

		IF @primaryKeyConstraintName = NULL
			BEGIN
				IF @showLogMessages = 1
					PRINT ''No existing primary key constraint name was found.  Must create a new name.''
			
				-- Must create the name to use for the new PK
				SET @primaryKeyConstraintName = ''PK_'' + @tableNameNoSchema

				IF @showLogMessages = 1
					PRINT ''Creating new name for primary key: '' + @primaryKeyConstraintName
			END
		ELSE
			BEGIN
				IF @showLogMessages = 1
					PRINT ''Existing primary key constraint name was found: '' + @primaryKeyConstraintName
			END

		IF @newPKConstraintNameOverride IS NOT NULL
		BEGIN
			set @primaryKeyConstraintName = @newPKConstraintNameOverride
		
				IF @showLogMessages = 1
					PRINT ''Using override name for the new primary key constraint: '' + @primaryKeyConstraintName
		END
			
			
		IF @createAsClustered = 1
			BEGIN

				SET @command = ''ALTER TABLE '' + @tableName + '' ADD CONSTRAINT ['' + @primaryKeyConstraintName + ''] PRIMARY KEY CLUSTERED('' + @newPKFieldNamesCommaDelimited + '')''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Creating new CLUSTERED primary key '' + @primaryKeyConstraintName + '' on table '' + @tableName + '' from field(s): '' + @newPKFieldNamesCommaDelimited
						PRINT @command
					END

				EXEC(@command)
			END
		ELSE
			BEGIN

				SET @command = ''ALTER TABLE '' + @tableName + '' ADD CONSTRAINT ['' + @primaryKeyConstraintName + ''] PRIMARY KEY NONCLUSTERED('' + @newPKFieldNamesCommaDelimited + '')''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Creating new NON-CLUSTERED primary key '' + @primaryKeyConstraintName + '' on table '' + @tableName + '' from field(s): '' + @newPKFieldNamesCommaDelimited
						PRINT @command
					END

				EXEC(@command)
			END
	
		IF @showLogMessages = 1
			PRINT ''********** END ctcsp__ChangePrimaryKey''

	')	-- ctcsp__ChangePrimaryKey




	

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp__AddIdentityField')
		DROP PROCEDURE dbo.ctcsp__AddIdentityField

	EXEC('
	CREATE PROCEDURE [dbo].ctcsp__AddIdentityField
	(
		@showLogMessages bit,
		@tableName nvarchar(MAX),
		@tableNameNoSchema nvarchar(200) = null,
		@newFieldName nvarchar(MAX),
		@useBigInt bit = 0,
		@startAtMostNegativeValue bit = 0,
		@makeNewFieldUniqueIndexed bit = 1,
		@makeNewUniqueIndexClustered bit = 0,
		@makeNewFieldSolePrimaryKey bit = 0,
		@makeNewPrimaryKeyNonClustered bit = 0,
		@newPKConstraintNameOverride NVARCHAR(200) = NULL
	)
	AS
		IF @showLogMessages = 1
			BEGIN
				PRINT ''********** BEGIN ctcsp__AddIdentityField''
				PRINT ''@tableName = '' + @tableName
				PRINT ''@newFieldName = '' + @newFieldName
			END

		DECLARE @command nvarchar(2048)

		SET NOCOUNT ON;
		
		IF @useBigInt = 0
			BEGIN

				if @showLogMessages = 1
					PRINT ''Adding INT identity field '' + @newFieldName + '' to table '' + @tableName

				if @startAtMostNegativeValue = 1
					BEGIN
						SET @command = ''ALTER TABLE '' + @tableName + '' add '' + @newFieldName + '' INT IDENTITY(-2,147,483,648,1)''

						IF @showLogMessages = 1
							PRINT @command

						EXEC(@command)
					END
				ELSE
					BEGIN
						SET @command = ''ALTER TABLE '' + @tableName + '' add '' + @newFieldName + '' INT IDENTITY(1,1)''

						IF @showLogMessages = 1
							PRINT @command

						EXEC(@command)
					END

			END
		ELSE
			BEGIN

				if @showLogMessages = 1
					PRINT ''Adding BIGINT identity field '' + @newFieldName + '' to table '' + @tableName

				if @startAtMostNegativeValue = 1
					BEGIN

						SET @command = ''ALTER TABLE '' + @tableName + '' add '' + @newFieldName + '' BIGINT IDENTITY(-9,223,372,036,854,775,808,1)''

						IF @showLogMessages = 1
							PRINT @command

						EXEC(@command)
					END
				ELSE
					BEGIN
						SET @command = ''ALTER TABLE '' + @tableName + '' add '' + @newFieldName + '' BIGINT IDENTITY(1,1)''

						IF @showLogMessages = 1
							PRINT @command

						EXEC(@command)
					END

			END

		IF @makeNewFieldUniqueIndexed = 1
			BEGIN

				DECLARE @newIndexName NVARCHAR(200) = ''IX_U_'' + @tableNameNoSchema + ''_ID''
				DECLARE @newIndexCommand NVARCHAR(MAX) 

				IF @makeNewUniqueIndexClustered = 0
					BEGIN
						SET @newIndexCommand = ''CREATE UNIQUE INDEX '' + @newIndexName + '' ON '' + @tableName + '' ('' + @newFieldName + '')'' 
					END
				ELSE
					BEGIN
						SET @newIndexCommand = ''CREATE CLUSTERED UNIQUE INDEX '' + @newIndexName + '' ON '' + @tableName + '' ('' + @newFieldName + '')'' 
					END
			
				if @showLogMessages = 1
					PRINT @newIndexCommand

				EXEC(@newIndexCommand)
			END

		IF @makeNewFieldSolePrimaryKey = 1
			BEGIN
				EXEC dbo.ctcsp__ChangePrimaryKey @showLogMessages, @tableName, @tableNameNoSchema, @newFieldName, @makeNewPrimaryKeyNonClustered, @newPKConstraintNameOverride
			END
	
		IF @showLogMessages = 1
			PRINT ''********** END ctcsp__AddIdentityField''

	')	-- ctcsp__AddIdentityField





	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp__AddChildTableIntFieldLinkToParentTable')
		DROP PROCEDURE dbo.ctcsp__AddChildTableIntFieldLinkToParentTable

	EXEC('
	CREATE PROCEDURE [dbo].ctcsp__AddChildTableIntFieldLinkToParentTable
	(
		@showLogMessages bit,
		@parentTableName nvarchar(MAX),
		@parentTableNameNoSchema NVARCHAR(200),
		@parentAlreadyLinkedFieldName nvarchar(MAX),
		@parentExistingFieldToLinkTo nvarchar(MAX),
		@childTableName nvarchar(MAX),
		@childTableNameNoSchema NVARCHAR(200),
		@childAlreadyLinkedFieldName nvarchar(MAX),
		@childFieldNameToAdd nvarchar(MAX),
		@useBigInt bit = 0,
		@deleteOldChildAlreadyLinkedField bit = 1,
		@deleteOldParentAlreadyLinkedField bit = 0,
		@relationNameToDelete nvarchar(200) = NULL,
		@relationToCreateNameOverride nvarchar(200) = NULL,
		@foreignKeyCascadesUpdates bit = 1,
		@foreignKeyCascadesDeletes bit = 1,
		@foreignKeyEnforceForReplication bit = 1,
		@foreignKeyConstraintEnforced bit = 1,
		@autoRenameNewChildFieldToDeletedLinkedChildField bit = 1,
		@childNewFieldToLinkToParentFinalName NVARCHAR(200) = NULL,
		@childNewFieldToLinkToParentAllowsNull bit = 0
	)
	AS
		SET NOCOUNT ON;

		IF @showLogMessages = 1
			BEGIN
				PRINT ''********** BEGIN ctcsp__AddChildTableIntFieldLinkToParentTable''
				PRINT ''@parentTableName = '' + @parentTableName
				PRINT ''@parentAlreadyLinkedFieldName = '' + @parentAlreadyLinkedFieldName
				PRINT ''@parentExistingFieldToLinkTo = '' + @parentExistingFieldToLinkTo
				PRINT ''@childTableName = '' + @childTableName
				PRINT ''@childAlreadyLinkedFieldName = '' + @childAlreadyLinkedFieldName
				PRINT ''@childFieldNameToAdd = '' + @childFieldNameToAdd
				PRINT ''@childNewFieldToLinkToParentFinalName = '' + @childNewFieldToLinkToParentFinalName
			END

		DECLARE @command nvarchar(2048)
		
		IF @useBigInt = 0
			BEGIN

				SET @command = ''ALTER TABLE '' + @childTableName + '' add '' + @childFieldNameToAdd + '' INT NULL''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Adding nullable INT field '' + @childFieldNameToAdd + '' to table '' + @childTableName
						PRINT @command
					END

				EXEC(@command)

			END
		ELSE
			BEGIN

				SET @command = ''ALTER TABLE '' + @childTableName + '' add '' + @childFieldNameToAdd + '' BIGINT NULL''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Adding nullable BIGINT field '' + @childFieldNameToAdd + '' to table '' + @childTableName
						PRINT @command
					END

				EXEC(@command)

			END
			

		SET @command = ''UPDATE '' + @childTableName + 
			 '' SET '' + @childTableName + ''.'' + @childFieldNameToAdd + '' = '' + 
			 @parentTableName + ''.'' + @parentExistingFieldToLinkTo + 
			 '' FROM '' + @childTableName + 
			 '' INNER JOIN '' +
			 @parentTableName + '' ON '' + @parentTableName + ''.'' + @parentAlreadyLinkedFieldName + '' = '' + 
			 @childTableName + ''.'' + @childAlreadyLinkedFieldName

		IF @showLogMessages = 1
			BEGIN
				PRINT ''Re-linking child table '' + @childTableName + '' to parent table '' + @parentTableName + '' using new fields.''
				PRINT @command
			END

		EXEC(@command)

		IF @childNewFieldToLinkToParentAllowsNull = 0
			BEGIN 
				IF @useBigInt = 0
					SET @command = ''ALTER TABLE '' + @childTableName + '' ALTER COLUMN '' + @childFieldNameToAdd + '' INT NOT NULL''
				ELSE
					SET @command = ''ALTER TABLE '' + @childTableName + '' ALTER COLUMN '' + @childFieldNameToAdd + '' BIGINT NOT NULL''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Making new child table ('' + @childTableName + '') field ('' + @childFieldNameToAdd + '') not nullable.''
						PRINT @command
					END

				EXEC(@command)
			END

		IF @relationNameToDelete IS NOT NULL
			BEGIN
				IF @showLogMessages = 1
					PRINT ''Finding existing relationship '' + @relationNameToDelete 
				
				DECLARE @foriegnKeyConstraintNameFound nvarchar(MAX)
				SELECT @foriegnKeyConstraintNameFound = name 
					FROM sys.foreign_keys  
					WHERE OBJECT_NAME(parent_object_id) = @childTableNameNoSchema AND name = @relationNameToDelete;  

				if @foriegnKeyConstraintNameFound IS NOT NULL
					BEGIN
						SET @command = ''ALTER TABLE '' + @childTableName + '' DROP CONSTRAINT ['' + @foriegnKeyConstraintNameFound + '']''

						IF @showLogMessages = 1
							BEGIN
								PRINT ''Existing relationship found.  Deleting it:  '' + @foriegnKeyConstraintNameFound 
								PRINT @command
							END

						EXEC(@command)
					END
				ELSE
					BEGIN
						if @showLogMessages = 1
								PRINT ''The relationship WAS NOT found:  '' + @relationNameToDelete 
					END
			END

		DECLARE @newRelationshipName nvarchar(200) = ''FK_'' + @childTableName + ''_'' + @parentTableName

		IF @relationToCreateNameOverride IS NOT NULL
			SET @newRelationshipName = @relationToCreateNameOverride

		DECLARE @createFKCommand nvarchar(MAX) = ''ALTER TABLE '' + @childTableName + '' WITH CHECK ADD CONSTRAINT ['' + @newRelationshipName + 
			 ''] FOREIGN KEY ('' + @childFieldNameToAdd + '') REFERENCES '' + @parentTableName + '' ('' + @parentExistingFieldToLinkTo + 
			 '')''

		IF @foreignKeyCascadesUpdates = 1
			SET @createFKCommand += '' ON UPDATE CASCADE''

		IF @foreignKeyCascadesDeletes = 1
			SET @createFKCommand += '' ON DELETE CASCADE''

		IF @foreignKeyEnforceForReplication = 0
			SET @createFKCommand += '' NOT FOR REPLICATION''

		IF @showLogMessages = 1
			BEGIN
				PRINT ''Building the relationship '' + @newRelationshipName + '' between the parent table '' + @parentTableName + '' and child table '' + @childTableName
				PRINT @createFKCommand
			END

		EXEC(@createFKCommand)

		IF @foreignKeyConstraintEnforced = 0
			BEGIN
				DECLARE @updateFKCommand NVARCHAR(200) = ''ALTER TABLE '' + @childTableName + '' NOCHECK CONSTRAINT '' + @newRelationshipName

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Disabling new constraint '' + @newRelationshipName
						PRINT @updateFKCommand
					END

				EXEC(@updateFKCommand)
			END
			 
		IF @deleteOldChildAlreadyLinkedField = 1
			BEGIN
				SET @command = ''ALTER TABLE '' + @childTableName + '' DROP COLUMN '' + @childAlreadyLinkedFieldName

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Deleting the field '' + @childAlreadyLinkedFieldName + '' from child table '' + @childTableName 
						PRINT @command
					END
			
				EXEC(@command)

				IF @autoRenameNewChildFieldToDeletedLinkedChildField = 1
					BEGIN

						SET @command = ''sp_rename '''''' + @childTableName + ''.'' + @childFieldNameToAdd + '''''', '''''' + @childAlreadyLinkedFieldName + '''''', ''''COLUMN''''''

						IF @showLogMessages = 1
							BEGIN
								PRINT ''Renaming the new field '' + @childFieldNameToAdd + '' back to the old linked field name '' + @childAlreadyLinkedFieldName
								PRINT @command
							END

						EXEC(@command)			

					END
					
			END

		IF @childNewFieldToLinkToParentFinalName IS NOT NULL
			BEGIN
			
				SET @command = ''sp_rename '''''' + @childTableName + ''.'' + @childFieldNameToAdd + '''''', '''''' + @childNewFieldToLinkToParentFinalName + '''''', ''''COLUMN''''''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Renaming the new field '' + @childFieldNameToAdd + '' to the new override name '' + @childNewFieldToLinkToParentFinalName
						PRINT @command
					END

				EXEC(@command)			
			
			END			
			
		IF @deleteOldParentAlreadyLinkedField = 1
			BEGIN
				SET @command = ''ALTER TABLE '' + @parentTableName + '' DROP COLUMN '' + @parentAlreadyLinkedFieldName

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Deleting the field '' + @parentAlreadyLinkedFieldName + '' from parent table '' + @parentTableName 
						PRINT @command
					END
			
				EXEC(@command)
			END

		IF @showLogMessages = 1
			PRINT ''********** END ctcsp__AddChildTableIntFieldLinkToParentTable''

	')	-- ctcsp__AddChildTableIntFieldLinkToParentTable





	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp__ReplaceSinglePrimaryKeyField')
		DROP PROCEDURE dbo.ctcsp__ReplaceSinglePrimaryKeyField

	EXEC('
	CREATE PROCEDURE [dbo].ctcsp__ReplaceSinglePrimaryKeyField
	(
		@showLogMessages bit,
		@tableName nvarchar(200),
		@tableNameNoSchema NVARCHAR(200),
		@existingFieldForNewPK nvarchar(200),
		@createAsClustered bit = 1,
		@oldPKFieldName nvarchar(200) = NULL,
		@deleteOldPKField bit = 1,
		@renameNewPKFieldToDeletedOldPKFieldName bit = 0,
		@newNameForOldPKFieldName NVARCHAR(100) = NULL,
		@newNameForNewPKFieldName NVARCHAR(100) = NULL,
		@newPKConstraintNameOverride NVARCHAR(200) = NULL
	)
	AS
		IF @showLogMessages = 1
			BEGIN
				PRINT ''********** BEGIN ctcsp__ReplaceSinglePrimaryKeyField''
				PRINT ''@tableName = '' + @tableName
				PRINT ''@existingFieldForNewPK = '' + @existingFieldForNewPK
				PRINT ''@newPKConstraintNameOverride = '' + @newPKConstraintNameOverride
			END

		SET NOCOUNT ON;

		DECLARE @command NVARCHAR(MAX) = ''ctcsp__ChangePrimaryKey '' + CAST(@showLogMessages AS NVARCHAR(MAX)) + '', '''''' + @tableName + '''''', '''''' + @tableNameNoSchema + '''''', '''''' + @existingFieldForNewPK + '''''', '' + CAST(@createAsClustered AS NVARCHAR(1)) + '', '''''' + @newPKConstraintNameOverride + ''''''''
	
		IF @showLogMessages = 1
			PRINT @command

		EXEC(@command)

		IF @deleteOldPKField = 1 AND @oldPKFieldName IS NOT NULL
			BEGIN

				SET @command = ''ALTER TABLE '' + @tableName + '' DROP COLUMN '' + @oldPKFieldName

				IF @showLogMessages = 1
					PRINT @command

				EXEC(@command)

				IF @renameNewPKFieldToDeletedOldPKFieldName = 1 AND @oldPKFieldName IS NOT NULL
					BEGIN

						SET @command = ''sp_rename '''''' + @tableName + ''.'' + @existingFieldForNewPK + '''''', '''''' + @oldPKFieldName + '''''', ''''COLUMN''''''

						IF @showLogMessages = 1
							PRINT @command

						EXEC(@command)

					END
			END

		IF @newNameForOldPKFieldName IS NOT NULL
			BEGIN
			
				SET @command = ''sp_rename '''''' + @tableName + ''.'' + @oldPKFieldName + '''''', '''''' + @newNameForOldPKFieldName + '''''', ''''COLUMN''''''

				IF @showLogMessages = 1
					PRINT @command

				EXEC(@command)
			
			END
			
		IF @newNameForNewPKFieldName IS NOT NULL
			BEGIN
			
				SET @command = ''sp_rename '''''' + @tableName + ''.'' + @existingFieldForNewPK + '''''', '''''' + @newNameForNewPKFieldName + '''''', ''''COLUMN''''''

				IF @showLogMessages = 1
					PRINT @command

				EXEC(@command)
			
			END			
			
		IF @showLogMessages = 1
			PRINT ''********** END ctcsp__ReplaceSinglePrimaryKeyField''

	')	-- ctcsp__ReplaceSinglePrimaryKeyField



	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp__DropColumn')
		DROP PROCEDURE dbo.ctcsp__DropColumn

	EXEC('
	CREATE PROCEDURE [dbo].ctcsp__DropColumn
	(
		@showLogMessages bit,
		@tableName nvarchar(200),
		@columnName nvarchar(200)
	)
	AS
		IF @showLogMessages = 1
			BEGIN
				PRINT ''********** BEGIN ctcsp__DropColumn''
				PRINT ''@tableName = '' + @tableName
				PRINT ''@columnName = '' + @columnName
			END

			DECLARE @command NVARCHAR(2048) = ''ALTER TABLE '' + @tableName + '' DROP COLUMN '' + @columnName

			IF @showLogMessages = 1
				PRINT @command

			EXEC(@command)

		IF @showLogMessages = 1
			PRINT ''********** END ctcsp__DropColumn''

	')	-- ctcsp__DropColumn

	
	
	 
	DECLARE @showLogMessages BIT = 1

	DECLARE @startNewIdentityAtMostNegativeValue bit = 0
	DECLARE @makeNewIdentityUniqueIndexed bit = 0
	DECLARE @makeNewIdentityUniqueIndexClustered bit = 0
	DECLARE @makeNewIdentitySolePrimaryKey bit = 0
	DECLARE	@makeNewIdentityPrimaryKeyNonClustered bit = 0
	DECLARE @parentTableName NVARCHAR(100)
	DECLARE @childTableName NVARCHAR(100)
	DECLARE @parentTableNameNoSchema NVARCHAR(200)
	DECLARE @childTableNameNoSchema NVARCHAR(200)
	DECLARE @tempNewIDFieldName NVARCHAR(10) = 'NewID'
	DECLARE @parentAlreadyLinkedField NVARCHAR(50) 
	DECLARE @childAlreadyLinkedField NVARCHAR(50)
	DECLARE @childNewFieldToLinkToParentTempName NVARCHAR(50)
	DECLARE @childNewFieldToLinkToParentFinalName NVARCHAR(200)
	DECLARE @childNewFieldToLinkToParentAllowsNull bit = 0
	DECLARE @useBigInt BIT = 0
	DECLARE @deleteOldChildAlreadyLinkedField BIT = 1
	DECLARE	@deleteOldParentAlreadyLinkedField BIT = 0
	DECLARE @foreignKeyNameToDelete NVARCHAR(100)
	DECLARE @foreignKeyNameToCreate NVARCHAR(100)
	DECLARE @foreignKeyCascadesUpdates BIT = 1
	DECLARE @foreignKeyCascadesDeletes BIT = 1
	DECLARE @foreignKeyEnforceForReplication BIT = 1
	DECLARE @foreignKeyConstraintEnforced BIT = 1
	DECLARE @autoRenameNewChildFieldToDeletedLinkedChildField BIT = 0
	DECLARE @NewPKIsClustered BIT = 1
	DECLARE @OldChildPKFieldName NVARCHAR(50)
	DECLARE @DeleteOldChildPKField BIT = 0
	DECLARE @RenameNewChildPKFieldToOldPKFieldName BIT = 0
	DECLARE @NewNameForOldChildPKFieldName NVARCHAR(100)
	DECLARE @NewNameForNewChildPKFieldName NVARCHAR(100)
	DECLARE @OldParentPKFieldName NVARCHAR(50)
	DECLARE @DeleteOldParentPKField BIT = 0
	DECLARE @RenameNewParentPKFieldToOldPKFieldName BIT = 0
	DECLARE @NewNameForOldParentPKFieldName NVARCHAR(100)
	DECLARE @NewNameForNewParentPKFieldName NVARCHAR(100)
	DECLARE @parentTableNewPKName NVARCHAR(200)
	DECLARE @childTableNewPKName NVARCHAR(200)
	DECLARE @command NVARCHAR(2048)
	
	

	IF (@palvers = 3 OR @snapvers = 3)  
		BEGIN


	PRINT ''
	PRINT ''
	PRINT ' PK AND RELATION CONVERSIONS BEGIN '
	PRINT ''
	PRINT ''
	
	

	IF @showLogMessages = 1
		PRINT 'PARENT TABLE:  pal.LogDocSession      CHILD TABLE:  pal.LogAddIn'

	SET @parentTableName = 'pal.LogDocSession'
	SET @parentTableNameNoSchema = 'LogDocSession'
	SET @childTableName = 'pal.LogAddIn'
	SET @childTableNameNoSchema = 'LogAddIn'
	SET @parentTableNewPKName = 'PK_' + @parentTableNameNoSchema
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @parentAlreadyLinkedField = 'Id'
	SET @childAlreadyLinkedField = 'DocSessionId'
	SET @childNewFieldToLinkToParentTempName = 'NewDocSessionID'  
	SET @childNewFieldToLinkToParentFinalName = 'DocSessionID'  
	SET @foreignKeyNameToDelete = 'FK_dbo.LogAddIns_dbo.LogDocuments_DocSessionId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema
	SET @OldChildPKFieldName = 'Id'
	SET @NewNameForOldChildPKFieldName = 'GUID'
	SET @NewNameForNewChildPKFieldName = 'ID'
	SET @OldParentPKFieldName = 'Id'
	SET @NewNameForOldParentPKFieldName = 'GUID'
	SET @NewNameForNewParentPKFieldName = 'ID'

	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName
		
	-- Parent table:  add a new auto-incrementing int identity field, NewID, to be the future PK of this table

	SET @makeNewIdentityUniqueIndexed = 1

	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @parentTableName, 
								 @parentTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @parentTableNewPKName
															 
	SET @makeNewIdentityUniqueIndexed = 0	
		
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull

	-- Drop the old GUID column, we dont need to keep it on this table.

	ALTER TABLE pal.LogAddIn DROP CONSTRAINT [DF__LogAddIns__Id]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogAddIn', 'GUID'



	IF @showLogMessages = 1
		PRINT 'CHILD TABLE CHANGE:  LogCrash'

	SET @childTableName = 'pal.LogCrash'
	SET @childTableNameNoSchema = 'LogCrash'
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @foreignKeyNameToDelete = 'FK_dbo.LogCrashes_dbo.LogDocuments_DocSessionId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema


	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName				
											 
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull												   
													   



	-- Drop the old GUID column, we don't need to keep it on this table.
	ALTER TABLE pal.LogCrash DROP CONSTRAINT [DF__LogCrashes__Id]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogCrash', 'GUID'



	IF @showLogMessages = 1
		PRINT 'CHILD TABLE CHANGE:  LogWarning'

	SET @childTableName = 'pal.LogWarning'
	SET @childTableNameNoSchema = 'LogWarning'
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @foreignKeyNameToDelete = 'FK_dbo.LogWarnings_dbo.LogDocuments_DocSessionId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema


	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName				
											 
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull													   

	-- Drop the old GUID column, we don't need to keep it on this table.
	ALTER TABLE pal.LogWarning DROP CONSTRAINT [DF__LogWarnings__Id__29572725]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogWarning', 'GUID'
													 



	IF @showLogMessages = 1
		PRINT 'CHILD TABLE CHANGE:  LogLink'

	SET @childTableName = 'pal.LogLink'
	SET @childTableNameNoSchema = 'LogLink'
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @foreignKeyNameToDelete = 'FK_dbo.LogLinks_dbo.LogDocuments_DocSessionId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema


	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName				
											 
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull												   

	-- Drop the old GUID column, we don't need to keep it on this table.
	ALTER TABLE pal.LogLink DROP CONSTRAINT [DF__LogLinks__Id__164452B1]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogLink', 'GUID'
													 


	IF @showLogMessages = 1
		PRINT 'CHILD TABLE CHANGE:  LogDocumentProjChange'

	SET @childTableName = 'pal.LogDocumentProjChange'
	SET @childTableNameNoSchema = 'LogDocumentProjChange'
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @foreignKeyNameToDelete = 'FK_LogDocumentProjChanges_LogDocSessions'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema


	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName				
											 
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull												   
												
	-- Drop the old GUID column, we don't need to keep it on this table.
	ALTER TABLE pal.LogDocumentProjChange DROP CONSTRAINT [DF__LogDocumentP__Id__2E1BDC42]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogDocumentProjChange', 'GUID'

	--------------------------------------------------------------------------------------------------------------
	-- PRINT Inserting OldProjectId guid

	--------------------------------------------------------------------------------------------------------------


	IF @showLogMessages = 1
		PRINT 'CHILD TABLE CHANGE:  LogViewType'

	SET @childTableName = 'pal.LogViewType'
	SET @childTableNameNoSchema = 'LogViewType'
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @foreignKeyNameToDelete = 'FK_dbo.LogViewTypes_dbo.LogDocuments_DocSessionId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema


	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName				
											 
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull												   

	-- Drop the old GUID column, we don't need to keep it on this table.
	ALTER TABLE pal.LogViewType DROP CONSTRAINT [DF__LogViewTypes__Id__25869641]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogViewType', 'GUID'

												
												
		

	IF @showLogMessages = 1
		PRINT 'CHILD TABLE CHANGE:  LogElement'

	SET @childTableName = 'pal.LogElement'
	SET @childTableNameNoSchema = 'LogElement'
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @foreignKeyNameToDelete = 'FK_dbo.LogElements_dbo.LogDocuments_DocSessionId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema


	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName				
											 
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull	
																								   
	-- Drop the old GUID column, we don't need to keep it on this table.
	ALTER TABLE pal.LogElement DROP CONSTRAINT [DF__LogElements__Id]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogElement', 'GUID'
										
			
												

	IF @showLogMessages = 1
		PRINT 'CHILD TABLE CHANGE:  LogEvent'

	DROP INDEX Idx_LogEvents_DocId_EventName_DateTime ON pal.LogEvent;  

	SET @childTableName = 'pal.LogEvent'
	SET @childTableNameNoSchema = 'LogEvent'
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @foreignKeyNameToDelete = 'FK_dbo.LogEvents_dbo.LogDocuments_DocSessionId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema


	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName				
											 
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull												   
												
	-- Drop the old GUID column, we don't need to keep it on this table.
	ALTER TABLE pal.LogEvent DROP CONSTRAINT [DF__LogEvents__Id__1273C1CD]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogEvent', 'GUID'
										
													

	IF @showLogMessages = 1
		PRINT 'CHILD TABLE CHANGE:  LogMachine'

	-- These are no longer needed
	DROP INDEX idx_dbo_LogMachines_DocIdUnique ON pal.LogMachine;  
	DROP INDEX Idx_LogMachines_DocId_DateTime ON pal.LogMachine;  

	SET @childTableName = 'pal.LogMachine'
	SET @childTableNameNoSchema = 'LogMachine'
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @foreignKeyNameToDelete = 'FK_dbo.LogMachines_dbo.LogDocuments_DocSessionId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema


	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName				
											 
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull												   
												
	-- Drop the old GUID column, we don't need to keep it on this table.
	ALTER TABLE pal.LogMachine DROP CONSTRAINT [DF__LogMachines__Id__1A14E395]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogMachine', 'GUID'
															
		
	IF @showLogMessages = 1
		PRINT 'CHILD TABLE CHANGE:  LogSummary'

	DROP INDEX Idx_LogSummaries_DocId_DateTime ON pal.LogSummary;  

	SET @childTableName = 'pal.LogSummary'
	SET @childTableNameNoSchema = 'LogSummary'
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @foreignKeyNameToDelete = 'FK_dbo.LogSummaries_dbo.LogDocuments_DocSessionId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema


	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName				
											 
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull												   

	-- Drop the old GUID column, we don't need to keep it on this table.
	ALTER TABLE pal.LogSummary DROP CONSTRAINT [DF__LogSummaries__Id__31EC6D26]
	EXEC ctcsp__DropColumn @showLogMessages, 'pal.LogSummary', 'GUID'
						
						
	-- Parent table:  Make the new auto-incrementing int ID field be the sole primary key
	-- But keep the old UniqueIdentifier field that was the primary key, renaming it
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @parentTableName, 
											 @parentTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldParentPKFieldName,
											 @DeleteOldParentPKField, 
											 @RenameNewParentPKFieldToOldPKFieldName,
											 @NewNameForOldParentPKFieldName,
											 @NewNameForNewParentPKFieldName,
											 @parentTableNewPKName
						
					
		

	IF @showLogMessages = 1
		PRINT 'PARENT TABLE:  asset.Project      CHILD TABLE:  asset.ProjectPath'

	SET @parentTableName = 'asset.Project'
	SET @parentTableNameNoSchema = 'Project'
	SET @childTableName = 'asset.ProjectPath'
	SET @childTableNameNoSchema = 'ProjectPath'
	SET @parentTableNewPKName = 'PK_' + @parentTableNameNoSchema
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @parentAlreadyLinkedField = 'Id'
	SET @childAlreadyLinkedField = 'ProjectId'
	SET @childNewFieldToLinkToParentTempName = 'NewProjectID'
	SET @childNewFieldToLinkToParentFinalName = 'ProjectID'  
	SET @foreignKeyNameToDelete = 'FK_dbo.ProjectModels_dbo.Projects_ProjectId'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema
	SET @OldChildPKFieldName = 'Id'
	SET @NewNameForOldChildPKFieldName = 'GUID'
	SET @NewNameForNewChildPKFieldName = 'ID'
	SET @OldParentPKFieldName = 'Id'
	SET @NewNameForOldParentPKFieldName = 'GUID'
	SET @NewNameForNewParentPKFieldName = 'ID'

	SET @makeNewIdentitySolePrimaryKey = 0

	-- Child table: Add a new auto-incrementing int ID field
	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @childTableName, 
								 @childTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @childTableNewPKName
								 

	-- Child table:  Make the new auto-incrementing int ID field be the sole primary key AND rename the old 
	-- Id field to GUID so we can rename the NewID field to ID, which will be the new PK.							 
	EXEC ctcsp__ReplaceSinglePrimaryKeyField @showLogMessages, 
											 @childTableName, 
											 @childTableNameNoSchema,
											 @tempNewIDFieldName, 
											 @NewPKIsClustered,
											 @OldChildPKFieldName,
											 @DeleteOldChildPKField, 
											 @RenameNewChildPKFieldToOldPKFieldName,
											 @NewNameForOldChildPKFieldName,
											 @NewNameForNewChildPKFieldName,
											 @childTableNewPKName
		
	SET @makeNewIdentitySolePrimaryKey = 0	
	set @parentTableNewPKName = 'PK_Project'
		
	-- Parent table:  add a new auto-incrementing int identity field, NewID, to be the future PK of this table

	SET @makeNewIdentityUniqueIndexed = 1

	EXEC ctcsp__AddIdentityField @showLogMessages, 
								 @parentTableName, 
								 @parentTableNameNoSchema,
								 @tempNewIDFieldName, 
								 @useBigInt, 
								 @startNewIdentityAtMostNegativeValue, 
								 @makeNewIdentityUniqueIndexed, 
								 @makeNewIdentityUniqueIndexClustered, 
								 @makeNewIdentitySolePrimaryKey, 
								 @makeNewIdentityPrimaryKeyNonClustered,
								 @parentTableNewPKName
								 
	---------------------------------------------------------------------------------------------------------------------
	PRINT ' Project Table now has int NewID field '
	PRINT ' Updating LogDocumentProjChanges to have int foriegn keys to Project table '

	IF NOT EXISTS (
		SELECT * 
		FROM   sys.columns 
		WHERE  object_id = OBJECT_ID(N'[pal].[LogDocumentProjChange]') 
				AND name = 'OldProjID'
	)
	BEGIN
		PRINT 'PAL - Adding OldProjID to LogDocumentProjChange'
		ALTER TABLE pal.LogDocumentProjChange
		ADD OldProjID [int] NOT NULL DEFAULT 0
	END

	IF NOT EXISTS (
		SELECT * 
		FROM   sys.columns 
		WHERE  object_id = OBJECT_ID(N'[pal].[LogDocumentProjChange]') 
				AND name = 'NewProjID'
	)
	BEGIN
		PRINT 'PAL - Adding NewProjID to LogDocumentProjChange'
		ALTER TABLE pal.LogDocumentProjChange
		ADD NewProjID [int] NOT NULL DEFAULT 0
	END

	BEGIN TRY
		EXEC('UPDATE t1
		SET t1.OldProjID = p1.NewID, t1.NewProjID = p2.NewID
		FROM pal.LogDocumentProjChange AS t1
		INNER JOIN asset.Project As p1 ON t1.OldProjectId = p1.Id 
		INNER JOIN asset.Project AS p2 ON t1.NewProjectId = p2.Id;')

		EXEC('ALTER TABLE pal.LogDocumentProjChange DROP COLUMN OldProjectId;')
		EXEC('ALTER TABLE pal.LogDocumentProjChange DROP COLUMN NewProjectId;')
		
	END TRY
	BEGIN CATCH
		PRINT ' Error Updating LogDocumentProjChanges to have int foriegn keys to Project table '
	END CATCH
	---------------------------------------------------------------------------------------------------------------------
										
	SET @makeNewIdentityUniqueIndexed = 0
		
	SET @deleteOldParentAlreadyLinkedField = 0
		
		
	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull

	-- Drop the old GUID column, we dont need to keep it on this table.'

	ALTER TABLE asset.ProjectPath DROP CONSTRAINT [DF__ProjectModel__Id__07020F21]

	EXEC ctcsp__DropColumn @showLogMessages, 'asset.ProjectPath', 'GUID'




	SET @childTableName = 'pal.LogDocSession'
	SET @childTableNameNoSchema = 'LogDocSession'
	SET @parentTableNewPKName = 'PK_' + @parentTableNameNoSchema
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @parentAlreadyLinkedField = 'Id'
	SET @childAlreadyLinkedField = 'ProjectId'
	SET @childNewFieldToLinkToParentTempName = 'NewProjectID'
	SET @childNewFieldToLinkToParentFinalName = 'ProjectID'  
	SET @foreignKeyNameToDelete = 'FK_LogDocSessions_Projects'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema
	SET @OldChildPKFieldName = 'Id'
	SET @NewNameForOldChildPKFieldName = 'GUID'
	SET @NewNameForNewChildPKFieldName = 'ID'
	SET @OldParentPKFieldName = 'Id'
	SET @NewNameForOldParentPKFieldName = 'GUID'
	SET @NewNameForNewParentPKFieldName = 'ID'
	
	SET @deleteOldParentAlreadyLinkedField = 0
	SET @foreignKeyCascadesUpdates = 0
	SET @foreignKeyCascadesDeletes = 0

	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull

													   
													   
		
	SET @childTableName = 'snapshot.ProjectFile'
	SET @childTableNameNoSchema = 'ProjectFile'
	SET @parentTableNewPKName = 'PK_' + @parentTableNameNoSchema
	SET @childTableNewPKName = 'PK_' + @childTableNameNoSchema
	SET @parentAlreadyLinkedField = 'Id'
	SET @childAlreadyLinkedField = 'ProjectID'
	SET @childNewFieldToLinkToParentTempName = 'NewProjectID'
	SET @childNewFieldToLinkToParentFinalName = 'ProjectID'  
	SET @foreignKeyNameToDelete = 'FK_ProjectFile_Projects'
	SET @foreignKeyNameToCreate = 'FK_' + @childTableNameNoSchema + '_' + @parentTableNameNoSchema
	SET @OldChildPKFieldName = 'ID'
	SET @NewNameForOldChildPKFieldName = 'GUID'
	SET @NewNameForNewChildPKFieldName = 'ID'
	SET @OldParentPKFieldName = 'Id'
	SET @NewNameForOldParentPKFieldName = 'GUID'
	SET @NewNameForNewParentPKFieldName = 'ID'
	
	SET @deleteOldParentAlreadyLinkedField = 0
	SET @foreignKeyCascadesUpdates = 0
	SET @foreignKeyCascadesDeletes = 0

	-- Re-link child table to parent table using new fields
	EXEC ctcsp__AddChildTableIntFieldLinkToParentTable @showLogMessages, 
													   @parentTableName, 
													   @parentTableNameNoSchema,
													   @parentAlreadyLinkedField, 
													   @tempNewIDFieldName, 
													   @childTableName, 
													   @childTableNameNoSchema,
													   @childAlreadyLinkedField, 
													   @childNewFieldToLinkToParentTempName, 
													   @useBigInt, 
													   @deleteOldChildAlreadyLinkedField, 
													   @deleteOldParentAlreadyLinkedField, 
													   @foreignKeyNameToDelete, 
													   @foreignKeyNameToCreate, 
													   @foreignKeyCascadesUpdates, 
													   @foreignKeyCascadesDeletes, 
													   @foreignKeyEnforceForReplication, 
													   @foreignKeyConstraintEnforced, 
													   @autoRenameNewChildFieldToDeletedLinkedChildField,
													   @childNewFieldToLinkToParentFinalName,
													   @childNewFieldToLinkToParentAllowsNull
													   
													   
													   
	EXEC ctcsp__ChangePrimaryKey @showLogMessages, @parentTableName, @parentTableNameNoSchema, 'NewID', 1, 'PK_Project'

	ALTER TABLE asset.Project DROP CONSTRAINT [DF__Projects__Id__403A8C7D]

	ALTER TABLE asset.Project DROP COLUMN Id

			DECLARE @oldFieldName NVARCHAR(MAX) = 'NewID'
			DECLARE @newFieldName NVARCHAR(MAX) = 'ID'

	SET @command = 'sp_rename ' + '''' + @parentTableName + '.' + @oldFieldName + '''' + ', ' + '''' + @newFieldName + '''' + ', ' + '''COLUMN'''

	IF @showLogMessages = 1
		PRINT @command

	EXEC(@command)


	-- Drop indexes that are no longer necessary
	
	DROP INDEX IX_ProjectPaths_CentralFilePathUnique ON asset.ProjectPath; 
	ALTER TABLE asset.Project DROP CONSTRAINT [UNQ_ProjectNumber]

	
	-- Must drop and later rebuild foreign key constraints that are tied to the extra index
	
	ALTER TABLE snapshot.ProjectFile DROP CONSTRAINT FK_ProjectFile_Project
	ALTER TABLE asset.ProjectPath DROP CONSTRAINT FK_ProjectPath_Project
	ALTER TABLE pal.LogDocSession DROP CONSTRAINT FK_LogDocSession_Project
	
	DROP INDEX IX_U_Project_ID ON asset.Project

	ALTER TABLE snapshot.ProjectFile WITH CHECK ADD CONSTRAINT [FK_ProjectFile_Project] FOREIGN KEY (ProjectID) REFERENCES asset.Project (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE asset.ProjectPath WITH CHECK ADD CONSTRAINT [FK_ProjectPath_Project] FOREIGN KEY (ProjectID) REFERENCES asset.Project (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogDocSession WITH CHECK ADD CONSTRAINT [FK_LogDocSession_Project] FOREIGN KEY (ProjectID) REFERENCES asset.Project (ID) ON UPDATE CASCADE ON DELETE CASCADE
	
	
	
	ALTER TABLE pal.LogAddIn DROP CONSTRAINT FK_LogAddIn_LogDocSession
	ALTER TABLE pal.LogCrash DROP CONSTRAINT FK_LogCrash_LogDocSession
	ALTER TABLE pal.LogDocumentProjChange DROP CONSTRAINT FK_LogDocumentProjChange_LogDocSession
	ALTER TABLE pal.LogElement DROP CONSTRAINT FK_LogElement_LogDocSession
	ALTER TABLE pal.LogEvent DROP CONSTRAINT FK_LogEvent_LogDocSession
	ALTER TABLE pal.LogLink DROP CONSTRAINT FK_LogLink_LogDocSession
	ALTER TABLE pal.LogMachine DROP CONSTRAINT FK_LogMachine_LogDocSession
	ALTER TABLE pal.LogSummary DROP CONSTRAINT FK_LogSummary_LogDocSession
	ALTER TABLE pal.LogViewType DROP CONSTRAINT FK_LogViewType_LogDocSession
	ALTER TABLE pal.LogWarning DROP CONSTRAINT FK_LogWarning_LogDocSession
	
	DROP INDEX IX_U_LogDocSession_ID ON pal.LogDocSession	
	
	ALTER TABLE pal.LogAddIn WITH CHECK ADD CONSTRAINT [FK_LogAddIn_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogCrash WITH CHECK ADD CONSTRAINT [FK_LogCrash_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogDocumentProjChange WITH CHECK ADD CONSTRAINT [FK_LogDocumentProjChange_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogElement WITH CHECK ADD CONSTRAINT [FK_LogElement_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogEvent WITH CHECK ADD CONSTRAINT [FK_LogEvent_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogLink WITH CHECK ADD CONSTRAINT [FK_LogLink_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogMachine WITH CHECK ADD CONSTRAINT [FK_LogMachine_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogSummary WITH CHECK ADD CONSTRAINT [FK_LogSummary_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogViewType WITH CHECK ADD CONSTRAINT [FK_LogViewType_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE
	ALTER TABLE pal.LogWarning WITH CHECK ADD CONSTRAINT [FK_LogWarning_LogDocSession] FOREIGN KEY (DocSessionID) REFERENCES pal.LogDocSession (ID) ON UPDATE CASCADE ON DELETE CASCADE

	CREATE NONCLUSTERED INDEX IX_LogDocSession_GUID ON pal.LogDocSession (GUID);
	

		---------------------------------------------------------------------------------------------------------------------------------------------
		-- MUST UPDATE THE GENERAL STORED PROCEDURES TO USE THE NEW ASSET SCHEMA AND SINGULARIZE PROC NAMES		
		---------------------------------------------------------------------------------------------------------------------------------------------
			--------------------------------------------------------------------------------
			PRINT 'PAL - Setting ProjectID = NULL'
			--------------------------------------------------------------------------------
			IF (select  is_nullable 
			FROM    sys.columns 
			WHERE   object_id = object_id('pal.LogDocSession') 
					and name = 'ProjectID') = 0
			BEGIN
				ALTER TABLE pal.LogDocSession ALTER COLUMN ProjectID [INT] NULL;
                ALTER TABLE pal.LogDocSession DROP CONSTRAINT FK_LogDocSession_Project; 

				UPDATE pal.LogDocSession
				SET ProjectID = NULL
				WHERE ProjectID = 1
				
				UPDATE pal.LogDocSession
				SET ProjectID = NULL
				WHERE ProjectID = 0
			END
			--------------------------------------------------------------------------------
			PRINT 'PAL - Setting ProjectID = NULL = END'
			--------------------------------------------------------------------------------
			--------------------------------------------------------------------------------
			PRINT 'Snapshot - Setting ProjectID = NULL'
			--------------------------------------------------------------------------------
			IF (select  is_nullable 
			FROM    sys.columns 
			WHERE   object_id = object_id('snapshot.ProjectFile') 
					and name = 'ProjectID') = 0
			BEGIN
				ALTER TABLE snapshot.ProjectFile ALTER COLUMN ProjectID [INT] NULL;
                ALTER TABLE snapshot.ProjectFile DROP CONSTRAINT FK_ProjectFile_Project; 
				UPDATE snapshot.ProjectFile
				SET ProjectID = NULL
				WHERE ProjectID = 1
			END
			
			-- SchemaData Table

			PRINT 'Global - Updating stored procedure for asset schema ctcsp_SchemaData_ReadTheOnlyRecord'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_SchemaData_ReadTheOnlyRecord')
				DROP PROCEDURE [asset].ctcsp_SchemaData_ReadTheOnlyRecord

			EXEC('
			CREATE PROCEDURE [asset].ctcsp_SchemaData_ReadTheOnlyRecord
			AS
				SET NOCOUNT ON;

				SELECT TOP 1 CurrentActivitySchemaVersion,
							 CurrentSnapshotSchemaVersion

			FROM asset.SchemaData
			')




			-- Projects table
		PRINT ''
		PRINT 'Global - Rename asset columns'

		IF EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[asset].[Project]') 
					AND name = 'LastUpdated'
		)
		BEGIN
			PRINT 'Global - Project renaming lastUpdated to UpdatedDate'
			EXEC sp_rename '[asset].[Project].LastUpdated' , 'UpdatedDate' , 'COLUMN'
		END	

		IF EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[asset].[Project]') 
					AND name = 'DateCreated'
		)
		BEGIN
			PRINT 'Global - Project renaming DateCreated to AddedDate'
			EXEC sp_rename '[asset].[Project].DateCreated' , 'AddedDate' , 'COLUMN'
		END	
		
		IF EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[asset].[ProjectPath]') 
					AND name = 'DateCreated'
		)
		BEGIN
			PRINT 'Global - Renaming  DateCreated to AddedDate in asset.ProjectPath'
			EXEC sp_rename '[asset].[ProjectPath].DateCreated' , 'AddedDate' , 'COLUMN'
		END	
			
		PRINT 'Global - End Rename Columns'
		PRINT ''
     --------------------------------------------------------------------------------
	--PRINT 'Rename Columns to ASSET Tables'
	--------------------------------------------------------------------------------
	
	 EXEC sp_rename 'asset.Project.ProjectStatus', 'ProjectPhase', 'COLUMN';  
		
	--------------------------------------------------------------------------------
	--PRINT 'Adding Columns to PAL Tables'
	--------------------------------------------------------------------------------


			PRINT 'Global - Updating stored procedure for asset schema ctcsp_Project_ReadByProjectNumber'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Projects_ReadByProjectNumber')
				DROP PROCEDURE [asset].ctcsp_Projects_ReadByProjectNumber

			EXEC('
			CREATE PROCEDURE [asset].ctcsp_Project_ReadByProjectNumber
			(
				@ProjectNumber nvarchar(50)
			)
			AS
				SET NOCOUNT ON;
				
			SELECT ID,
				   Office,
				   ProjectNumber,
				   ProjectName,
				   BuildingName,
				   ClientName,
				   StreetAddress,
				   StreetAddress2,
				   StreetAddress3,
				   ProjectPhase,
				   ProjectIssueDate,
				   Author,
				   City,
				   StateOrProvince,
				   PostalCode,
				   CountryName,
				   OrgName,
				   OrgDescription,
				   ProjectImage,
				   AddedDate
				   UpdatedDate,
				   CompanyID,
				   AddedByUserID,
				   UpdatedByUserID,
				   Status
				   
			FROM asset.Project

			WHERE (ProjectNumber = @ProjectNumber)
			')



			PRINT 'Global - Updating stored procedure for asset schema ctcsp_Project_ReadByProjectName'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Projects_ReadByProjectName')
				DROP PROCEDURE [asset].ctcsp_Projects_ReadByProjectName

			EXEC('
			CREATE PROCEDURE [asset].ctcsp_Project_ReadByProjectName
			(
				@ProjectName nvarchar(255)
			)
			AS
				SET NOCOUNT ON;
				
			SELECT ID,
				   Office,
				   ProjectNumber,
				   ProjectName,
				   BuildingName,
				   ClientName,
				   StreetAddress,
				   StreetAddress2,
				   StreetAddress3,
				   ProjectPhase,
				   ProjectIssueDate,
				   Author,
				   City,
				   StateOrProvince,
				   PostalCode,
				   CountryName,
				   OrgName,
				   OrgDescription,
				   ProjectImage,
				   AddedDate
				   UpdatedDate,
				   CompanyID,
				   AddedByUserID,
				   UpdatedByUserID,
				   Status
				   
			FROM asset.Project

			WHERE (ProjectName = @ProjectName)
			')


			PRINT 'Global - Updating stored procedure for asset schema ctcsp_Project_ReadByClientName'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Projects_ReadByClientName')
				DROP PROCEDURE [asset].ctcsp_Projects_ReadByClientName

			EXEC('	
			CREATE PROCEDURE [asset].ctcsp_Project_ReadByClientName
			(
				@ClientName nvarchar(50)
			)
			AS
				SET NOCOUNT ON;
				
			SELECT ID,
				   Office,
				   ProjectNumber,
				   ProjectName,
				   BuildingName,
				   ClientName,
				   StreetAddress,
				   StreetAddress2,
				   StreetAddress3,
				   ProjectPhase,
				   ProjectIssueDate,
				   Author,
				   City,
				   StateOrProvince,
				   PostalCode,
				   CountryName,
				   OrgName,
				   OrgDescription,
				   ProjectImage,
				   AddedDate
				   UpdatedDate,
				   CompanyID,
				   AddedByUserID,
				   UpdatedByUserID,
				   Status
				   
			FROM asset.Project

			WHERE (ClientName = @ClientName)
			')


			PRINT 'Global - Updating stored procedure for asset schema ctcsp_Project_ReadByAll'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Projects_ReadByAll')
				DROP PROCEDURE [asset].ctcsp_Projects_ReadByAll

			EXEC('
			CREATE PROCEDURE [asset].ctcsp_Project_ReadByAll
			AS
				SET NOCOUNT ON;
				
			SELECT ID,
				   Office,
				   ProjectNumber,
				   ProjectName,
				   BuildingName,
				   ClientName,
				   StreetAddress,
				   StreetAddress2,
				   StreetAddress3,
				   ProjectPhase,
				   ProjectIssueDate,
				   Author,
				   City,
				   StateOrProvince,
				   PostalCode,
				   CountryName,
				   OrgName,
				   OrgDescription,
				   ProjectImage,
				   AddedDate
				   UpdatedDate,
				   CompanyID,
				   AddedByUserID,
				   UpdatedByUserID,
				   Status
				   
			FROM asset.Project
			')

			
			
			PRINT 'Global - Updating stored procedure for asset schema ctcsp_Project_ReadByID'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Project_ReadByID')
				DROP PROCEDURE [asset].ctcsp_Project_ReadByID

			EXEC('
			CREATE PROCEDURE [asset].ctcsp_Project_ReadByID
			(
				@ID int
			)
			AS
				SET NOCOUNT ON;
				
			SELECT ID,
				   Office,
				   ProjectNumber,
				   ProjectName,
				   BuildingName,
				   ClientName,
				   StreetAddress,
				   StreetAddress2,
				   StreetAddress3,
				   ProjectPhase,
				   ProjectIssueDate,
				   Author,
				   City,
				   StateOrProvince,
				   PostalCode,
				   CountryName,
				   OrgName,
				   OrgDescription,
				   ProjectImage,
				   AddedDate,
				   UpdatedDate,
				   CompanyID,
				   AddedByUserID,
				   UpdatedByUserID,
				   Status
				   
			FROM asset.Project
			
			WHERE (ID = @ID)
			
			')			
		
			

			PRINT 'Global - Updating stored procedure for asset schema ctcsp_Project_Create'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Projects_Create')
				DROP PROCEDURE [asset].ctcsp_Projects_Create

			EXEC('
			CREATE PROCEDURE [asset].ctcsp_Project_Create
			(
				-- ID is auto generated
				@Office nvarchar(50),
				@ProjectNumber nvarchar(50),
				@ProjectName nvarchar(255),
				@BuildingName nvarchar(100),
				@ClientName nvarchar(50),
				@StreetAddress nvarchar(100),
				@StreetAddress2 nvarchar(100),
				@StreetAddress3 nvarchar(100),
				@ProjectStatus nvarchar(25),
				@ProjectIssueDate datetime,
				@Author nvarchar(50),
				@City nvarchar(100),
				@StateOrProvince nvarchar(25),
				@PostalCode nvarchar(12),
				@CountryName nvarchar(35),
				@OrgName nvarchar(100),
				@OrgDescription nvarchar(2048),
				@ProjectImage varbinary(MAX),
				@DateCreated datetime,
				@LastUpdated datetime,
				@CompanyID int,
				@AddedByUserID int,
				@UpdatedByUserID int,
				@Status int
			)
			AS
				SET NOCOUNT OFF;
				
			INSERT INTO [asset].[Project] (
				[Office],
				[ProjectNumber],
				[ProjectName],
				[BuildingName],
				[ClientName],
				[StreetAddress],
				[StreetAddress2],
				[StreetAddress3],
				[ProjectPhase],
				[ProjectIssueDate],
				[Author],
				[City],
				[StateOrProvince],
				[PostalCode],
				[CountryName],
				[OrgName],
				[OrgDescription],
				[ProjectImage],
				[AddedDate],
				[UpdatedDate],
				[CompanyID],
				[AddedByUserID],
				[UpdatedByUserID],
				[Status]
			) 
				
			VALUES (
				@Office,
				@ProjectNumber,
				@ProjectName,
				@BuildingName,
				@ClientName,
				@StreetAddress,
				@StreetAddress2,
				@StreetAddress3,
				@ProjectStatus,
				@ProjectIssueDate,
				@Author,
				@City,
				@StateOrProvince,
				@PostalCode,
				@CountryName,
				@OrgName,
				@OrgDescription,
				@ProjectImage,
				@DateCreated,
				@LastUpdated,
				@CompanyID,
				@AddedByUserID,
				@UpdatedByUserID,
				@Status
			);
				
			SELECT ID,
				   Office,
				   ProjectNumber,
				   ProjectName,
				   BuildingName,
				   ClientName,
				   StreetAddress,
				   StreetAddress2,
				   StreetAddress3,
				   ProjectPhase,
				   ProjectIssueDate,
				   Author,
				   City,
				   StateOrProvince,
				   PostalCode,
				   CountryName,
				   OrgName,
				   OrgDescription,
				   ProjectImage,
				   AddedDate
				   UpdatedDate,
				   CompanyID,
				   AddedByUserID,
				   UpdatedByUserID,
				   Status

			FROM asset.Project 

			WHERE (ID = SCOPE_IDENTITY())
			')


			PRINT 'Global - Updating stored procedure for asset schema ctcsp_Project_Update'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Projects_Update')
				DROP PROCEDURE [asset].ctcsp_Projects_Update

			EXEC('
			CREATE PROCEDURE [asset].ctcsp_Project_Update
			(
				@ID int,
				@Office nvarchar(50),
				@ProjectNumber nvarchar(50),
				@ProjectName nvarchar(255),
				@BuildingName nvarchar(100),
				@ClientName nvarchar(50),
				@StreetAddress nvarchar(100),
				@StreetAddress2 nvarchar(100),
				@StreetAddress3 nvarchar(100),
				@ProjectStatus nvarchar(25),
				@ProjectIssueDate datetime,
				@Author nvarchar(50),
				@City nvarchar(100),
				@StateOrProvince nvarchar(25),
				@PostalCode nvarchar(12),
				@CountryName nvarchar(35),
				@OrgName nvarchar(100),
				@OrgDescription nvarchar(2048),
				@ProjectImage varbinary(MAX),
				@DateCreated datetime,
				@LastUpdated datetime,
				@CompanyID int,
				@AddedByUserID int,
				@UpdatedByUserID int,
				@Status	int
			)
			AS
				SET NOCOUNT OFF;

			UPDATE [asset].[Project] SET 
				[Office] = @Office,
				[ProjectNumber] = @ProjectNumber,
				[ProjectName] = @ProjectName,
				[BuildingName] = @BuildingName,
				[ClientName] = @ClientName,
				[StreetAddress] = @StreetAddress,
				[StreetAddress2] = @StreetAddress2,
				[StreetAddress3] = @StreetAddress3,
				[ProjectPhase] = @ProjectStatus,
				[ProjectIssueDate] = @ProjectIssueDate,
				[Author] = @Author,
				[City] = @City,
				[StateOrProvince] = @StateOrProvince,
				[PostalCode] = @PostalCode,
				[CountryName] = @CountryName,
				[OrgName] = @OrgName,
				[OrgDescription] = @OrgDescription,
				[ProjectImage] = @ProjectImage,
				[AddedDate] = @DateCreated,
				[UpdatedDate] = @LastUpdated,
				[CompanyID] = @CompanyID,
				[AddedByUserID] = @AddedByUserID,
				[UpdatedByUserID] = @UpdatedByUserID,
				[Status] = @Status
				
			WHERE (([ID] = @ID));
				
			SELECT ID,
				   Office,
				   ProjectNumber,
				   ProjectName,
				   BuildingName,
				   ClientName,
				   StreetAddress,
				   StreetAddress2,
				   StreetAddress3,
				   ProjectPhase,
				   ProjectIssueDate,
				   Author,
				   City,
				   StateOrProvince,
				   PostalCode,
				   CountryName,
				   OrgName,
				   OrgDescription,
				   ProjectImage,
				   AddedDate
				   UpdatedDate,
				   CompanyID,
				   AddedByUserID,
				   UpdatedByUserID,
				   Status
				   
			FROM Project

			WHERE (ID = @ID)
			')


			PRINT 'Global - Updating stored procedure for asset schema ctcsp_Project_Delete'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Projects_Delete')
				DROP PROCEDURE [asset].ctcsp_Projects_Delete

			EXEC('
			CREATE PROCEDURE [asset].ctcsp_Project_Delete
			(
				@ID int
			)
			AS
				SET NOCOUNT OFF;
				
			DELETE FROM [asset].[Project] 

			WHERE (([ID] = @ID))
			')
		
			
		END  -- Must update general stored procs from schema version 3 to 4
	
	IF @snapvers = 3 
	BEGIN

	---------------------------------------------------------------------------------------------------------------------------------------------
	-- MUST UPDATE THE SNAPSHOT STORED PROCEDURES TO USE THE NEW SNAPSHOT SCHEMA
	---------------------------------------------------------------------------------------------------------------------------------------------


	-- Discipline table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_Discipline_ReadByElementDefinitionID_ProjectFileSnapshotID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Discipline_ReadByElementDefinitionID_ProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_Discipline_ReadByElementDefinitionID_ProjectFileSnapshotID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_Discipline_ReadByElementDefinitionID_ProjectFileSnapshotID
	(
		@ElementDefinitionID uniqueidentifier,
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ElementDefinitionID, 
			ProjectFileSnapshotID, 
			Name 
			
	FROM snapshot.Discipline 

	WHERE ElementDefinitionID = @ElementDefinitionID AND ProjectFileSnapshotID = @ProjectFileSnapshotID
	')


	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_Discipline_ReadByElementDefinitionID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Discipline_ReadByElementDefinitionID')
		DROP PROCEDURE [snapshot].ctcsp_Discipline_ReadByElementDefinitionID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_Discipline_ReadByElementDefinitionID
	(
		@ElementDefinitionID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ElementDefinitionID, 
			ProjectFileSnapshotID, 
			Name 
			
	FROM snapshot.Discipline 

	WHERE ElementDefinitionID = @ElementDefinitionID
	')


		
	-- ElementDefinition table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ElementDefinition_ReadByProjectFileSnapshotID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementDefinition_ReadByProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_ElementDefinition_ReadByProjectFileSnapshotID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementDefinition_ReadByProjectFileSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT ID,
		   ElementID, 
		   ProjectFileSnapshotID, 
		   Name, 
		   CategoryID,
		   CategoryName, 
		   CategoryIsAnnotation, 
		   CategoryIsAnnotationDisplayName,
		   CategoryIsInstanceCreatable, 
		   CategoryIsFamilyFileLoadable, 
		   IsSystemFamily,
		   TypeCount,
		   InstanceCount,
		   ParameterValueCount,
		   UniqueID
		   
	FROM snapshot.ElementDefinition 

	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID
	')	
		
		
		
	-- ElementInstance table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ElementInstance_ReadByElementDefinitionID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_ReadByElementDefinitionID')
		DROP PROCEDURE [snapshot].ctcsp_ElementInstance_ReadByElementDefinitionID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementInstance_ReadByElementDefinitionID
	(
		@ElementDefinitionID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ID,
			ElementDefinitionID,
			ElementTypeID,
			ElementID, 
			ProjectFileSnapshotID,
			ElementDefinitionName,
			ElementTypeName,
			CategoryName, 
			CreatedPhase, 
			DemolishedPhase, 
			IsDesignOptionPrimary, 
			LevelElementID, 
			LevelName, 
			OwnerViewElementID, 
			OwnerViewName, 
			ParameterValueCount,
			WarningCount,
			WorksetID, 
			WorksetName, 
			ModelUpdateStatus, 
			Creator, 
			CurrentOwner, 
			LastChangedBy,
			UniqueID
			
	FROM snapshot.ElementInstance 

	WHERE (ElementDefinitionID = @ElementDefinitionID)
	')


	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ElementInstance_ReadByElementTypeID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_ReadByElementTypeID')
		DROP PROCEDURE [snapshot].ctcsp_ElementInstance_ReadByElementTypeID
		
	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementInstance_ReadByElementTypeID
	(
		@ElementTypeID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ID,
			ElementDefinitionID,
			ElementTypeID,
			ElementID, 
			ProjectFileSnapshotID,
			ElementDefinitionName,
			ElementTypeName,
			CategoryName, 
			CreatedPhase, 
			DemolishedPhase, 
			IsDesignOptionPrimary, 
			LevelElementID, 
			LevelName, 
			OwnerViewElementID, 
			OwnerViewName, 
			ParameterValueCount,
			WarningCount,
			WorksetID, 
			WorksetName, 
			ModelUpdateStatus, 
			Creator, 
			CurrentOwner, 
			LastChangedBy,
			UniqueID
			
	FROM snapshot.ElementInstance 

	WHERE (ElementTypeID = @ElementTypeID)

	')

		
		
		
	-- ElementParameterValue table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ElementParameterValue_ReadByElementDefinitionID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementParameterValue_ReadByElementDefinitionID')
		DROP PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadByElementDefinitionID


	EXEC('	
	CREATE PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadByElementDefinitionID
	(
		@ElementDefinitionID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;

	SELECT 	ID,
			ParameterDefinitionElementID, 
			ProjectFileSnapshotID, 
			ElementDefinitionID, 
			IsFromElementDefinition, 
			IsFromElementType, 
			IsFromElementInstance, 
			ElementInstanceID, 
			ElementTypeID, 
			ParameterName, 
			ElementDefinitionName, 
			ElementTypeName, 
			IsTypeParameter, 
			IsInstanceParameter, 
			IsPhaseSpecificInstanceParameter, 
			Phase, 
			IsProjectParameter, 
			IsBuiltIn, 
			ParameterGroup, 
			ParameterType, 
			FamilyTypeParameterCategory, 
			StorageType, 
			IsShared, 
			SharedParameterGUID, 
			HasValue, 
			IsReadOnly, 
			ValueAsElementID, 
			ValueAsString, 
			ValueInSystemUnits, 
			ValueInDisplayUnits, 
			DisplayUnitsSymbol, 
			IsDisplayUnitsSymbolPrefixed
			
	FROM snapshot.ElementParameterValue 

	WHERE ElementDefinitionID = @ElementDefinitionID
	')




	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ElementParameterValue_ReadByID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementParameterValue_ReadByID')
		DROP PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadByID


	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadByID
	(
		@ID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;

	SELECT 	ID,
			ParameterDefinitionElementID, 
			ProjectFileSnapshotID, 
			ElementDefinitionID, 
			IsFromElementDefinition, 
			IsFromElementType, 
			IsFromElementInstance, 
			ElementInstanceID, 
			ElementTypeID, 
			ParameterName, 
			ElementDefinitionName, 
			ElementTypeName, 
			IsTypeParameter, 
			IsInstanceParameter, 
			IsPhaseSpecificInstanceParameter, 
			Phase, 
			IsProjectParameter, 
			IsBuiltIn, 
			ParameterGroup, 
			ParameterType, 
			FamilyTypeParameterCategory, 
			StorageType, 
			IsShared, 
			SharedParameterGUID, 
			HasValue, 
			IsReadOnly, 
			ValueAsElementID, 
			ValueAsString, 
			ValueInSystemUnits, 
			ValueInDisplayUnits, 
			DisplayUnitsSymbol, 
			IsDisplayUnitsSymbolPrefixed
			
	FROM snapshot.ElementParameterValue 

	WHERE ID = @ID
	')


	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ElementParameterValue_ReadTypeParameterValuesForType'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementParameterValue_ReadTypeParameterValuesForType')
		DROP PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadTypeParameterValuesForType

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadTypeParameterValuesForType
	(
		@ElementTypeID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;

	SELECT 	ID,
			ParameterDefinitionElementID, 
			ProjectFileSnapshotID, 
			ElementDefinitionID, 
			IsFromElementDefinition, 
			IsFromElementType, 
			IsFromElementInstance, 
			ElementInstanceID, 
			ElementTypeID, 
			ParameterName, 
			ElementDefinitionName, 
			ElementTypeName, 
			IsTypeParameter, 
			IsInstanceParameter, 
			IsPhaseSpecificInstanceParameter, 
			Phase, 
			IsProjectParameter, 
			IsBuiltIn, 
			ParameterGroup, 
			ParameterType, 
			FamilyTypeParameterCategory, 
			StorageType, 
			IsShared, 
			SharedParameterGUID, 
			HasValue, 
			IsReadOnly, 
			ValueAsElementID, 
			ValueAsString, 
			ValueInSystemUnits, 
			ValueInDisplayUnits, 
			DisplayUnitsSymbol, 
			IsDisplayUnitsSymbolPrefixed
			
	FROM snapshot.ElementParameterValue 

	WHERE ElementTypeID = @ElementTypeID AND
		  IsFromElementType = 1 
	')



	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ElementParameterValue_ReadInstanceParameterValues'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementParameterValue_ReadInstanceParameterValues')
		DROP PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadInstanceParameterValues

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadInstanceParameterValues
	(
		@ElementInstanceID uniqueidentifier,
		@IncludeTypeParameterValues bit
	)
	AS
		SET NOCOUNT ON;

	IF (@IncludeTypeParameterValues = 1)

		SELECT 	ID,
				ParameterDefinitionElementID, 
				ProjectFileSnapshotID, 
				ElementDefinitionID, 
				IsFromElementDefinition, 
				IsFromElementType, 
				IsFromElementInstance, 
				ElementInstanceID, 
				ElementTypeID, 
				ParameterName, 
				ElementDefinitionName, 
				ElementTypeName, 
				IsTypeParameter, 
				IsInstanceParameter, 
				IsPhaseSpecificInstanceParameter, 
				Phase, 
				IsProjectParameter, 
				IsBuiltIn, 
				ParameterGroup, 
				ParameterType, 
				FamilyTypeParameterCategory, 
				StorageType, 
				IsShared, 
				SharedParameterGUID, 
				HasValue, 
				IsReadOnly, 
				ValueAsElementID, 
				ValueAsString, 
				ValueInSystemUnits, 
				ValueInDisplayUnits, 
				DisplayUnitsSymbol, 
				IsDisplayUnitsSymbolPrefixed
			
		FROM snapshot.ElementParameterValue 

		-- Need IsFromElementType = 0 to exclue parameter values that exist from the type definition alone (whether
		-- or not any instances existed for that type)

		WHERE ElementInstanceID = @ElementInstanceID AND
			  IsFromElementType = 0;

	ELSE

		SELECT 	ID,
				ParameterDefinitionElementID, 
				ProjectFileSnapshotID, 
				ElementDefinitionID, 
				IsFromElementDefinition, 
				IsFromElementType, 
				IsFromElementInstance, 
				ElementInstanceID, 
				ElementTypeID, 
				ParameterName, 
				ElementDefinitionName, 
				ElementTypeName, 
				IsTypeParameter, 
				IsInstanceParameter, 
				IsPhaseSpecificInstanceParameter, 
				Phase, 
				IsProjectParameter, 
				IsBuiltIn, 
				ParameterGroup, 
				ParameterType, 
				FamilyTypeParameterCategory, 
				StorageType, 
				IsShared, 
				SharedParameterGUID, 
				HasValue, 
				IsReadOnly, 
				ValueAsElementID, 
				ValueAsString, 
				ValueInSystemUnits, 
				ValueInDisplayUnits, 
				DisplayUnitsSymbol, 
				IsDisplayUnitsSymbolPrefixed
			
		FROM snapshot.ElementParameterValue 


		WHERE ElementInstanceID = @ElementInstanceID AND
			  IsFromElementType = 0 AND
			  IsTypeParameter = 0;
	')


		
		
		
	-- ElementType table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ElementType_ReadByElementDefinitionID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementType_ReadByElementDefinitionID')
		DROP PROCEDURE [snapshot].ctcsp_ElementType_ReadByElementDefinitionID

	EXEC('	
	CREATE PROCEDURE [snapshot].ctcsp_ElementType_ReadByElementDefinitionID
	(
		@ElementDefinitionID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT ID,
		   ElementDefinitionID,
		   ElementID, 
		   ProjectFileSnapshotID, 
		   Name, 
		   IsSystemFamilyType, 
		   InstanceCount,
		   ParameterValueCount,
		   UniqueID
		   
	FROM snapshot.ElementType 

	WHERE  ElementDefinitionID = @ElementDefinitionID
	')


		
		
		
	-- GroupInstance table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_GroupInstance_ReadByProjectFileSnapshotID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstance_ReadByProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_GroupInstance_ReadByProjectFileSnapshotID


	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_GroupInstance_ReadByProjectFileSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ID,
			ElementID, 
			ProjectFileSnapshotID, 
			GroupTypeElementID,
			GroupTypeName, 
			OwnerViewElementInstanceID, 
			OwnerViewName,
			LevelElementInstanceID, 
			LevelName, 
			MemberElementCount, 
			IsDetailGroup,
			IsDetailGroupDisplayName,
			ParentModelGroupName,
			ParameterValueCount,
			GroupTypeUniqueID,
			GroupInstanceUniqueID
			
	FROM snapshot.GroupInstance 

	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID
	')


		
		
		
	-- GroupInstanceElementInstanceLookup table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_GroupInstanceElementInstanceLookup_ReadByProjectSnapshotID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstanceElementInstanceLookup_ReadByProjectSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_GroupInstanceElementInstanceLookup_ReadByProjectSnapshotID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_GroupInstanceElementInstanceLookup_ReadByProjectSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	GroupInstanceID, 
			ElementInstanceID, 
			ProjectFileSnapshotID 
			
	FROM snapshot.GroupInstanceElementInstanceLookup 

	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID
	')


		
		
		
	-- GroupInstanceParameterValue table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_GroupInstanceParameterValue_ReadByGroupInstanceID'
		
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_GroupInstanceParameterValue_ReadByGroupInstanceID')
		DROP PROCEDURE [snapshot].ctcsp_GroupInstanceParameterValue_ReadByGroupInstanceID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_GroupInstanceParameterValue_ReadByGroupInstanceID
	(
		@GroupInstanceID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ID,
			GroupInstanceID, 
			ProjectFileSnapshotID,
			ParameterElementID,
			ParameterName, 
			ParameterGroup, 
			ParameterType, 
			StorageType, 
			IsInstance, 
			IsReadOnly, 
			IsBuiltIn, 
			FamilyTypeParameterCategory, 
			HasValue, 
			ValueAsElementID, 
			ValueAsString, 
			ValueInSystemUnits, 
			ValueInDisplayUnits, 
			DisplayUnitsSymbol,
			IsDisplayUnitsSymbolPrefixed
			
	FROM snapshot.GroupInstanceParameterValue 

	WHERE GroupInstanceID = @GroupInstanceID 
	')


		
		
		
	-- LinePattern table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_LinePattern_ReadByProjectFileSnapshotID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_LinePattern_ReadByProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_LinePattern_ReadByProjectFileSnapshotID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_LinePattern_ReadByProjectFileSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;

	SELECT 	ID, 
			ProjectFileSnapshotID, 
			Name,
			IsUsed
			
	FROM snapshot.LinePattern 

	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID
	')


		
		
		
	-- ProjectFile table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectFile_ReadByProjectID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadByProjectID')
		DROP PROCEDURE [snapshot].ctcsp_ProjectFile_ReadByProjectID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectFile_ReadByProjectID
	(
		@ProjectID int
	)
	AS
		SET NOCOUNT ON;
		
	SELECT ID, 
		   CentralOrSingleUserProjectFileName,
		   CompanyID,
		   ProjectID,
		   IsWorkshared,
		   ShortFileName
		   
	FROM snapshot.ProjectFile

	WHERE (ProjectID = @ProjectID)
	')


	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectFile_ReadByCentralOrSingleUserProjectFileName'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadByCentralOrSingleUserProjectFileName')
		DROP PROCEDURE [snapshot].ctcsp_ProjectFile_ReadByCentralOrSingleUserProjectFileName

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectFile_ReadByCentralOrSingleUserProjectFileName
	(
		@CentralOrSingleUserProjectFileName nvarchar(255)
	)
	AS
		SET NOCOUNT ON;
		
	SELECT CentralOrSingleUserProjectFileName,
		   CompanyID,
		   ID,
		   IsWorkshared,
		   ProjectID,
		   ShortFileName
		   
	FROM snapshot.ProjectFile

	WHERE (CentralOrSingleUserProjectFileName = @CentralOrSingleUserProjectFileName)
	')


	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectFile_ReadByAll'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadByAll')
		DROP PROCEDURE [snapshot].ctcsp_ProjectFile_ReadByAll

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectFile_ReadByAll
	AS
		SET NOCOUNT ON;
		
		SELECT ID,
			   CentralOrSingleUserProjectFileName,
			   CompanyID,
			   ProjectID,
			   IsWorkshared,
			   ShortFileName
			   
	FROM snapshot.ProjectFile
	')

	
	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectFile_ReadByCompanyID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadByCompanyID')
		DROP PROCEDURE [snapshot].ctcsp_ProjectFile_ReadByCompanyID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectFile_ReadByCompanyID
	(
		@CompanyID int
	)
	AS
		SET NOCOUNT ON;
		
	SELECT CentralOrSingleUserProjectFileName,
		   CompanyID,
		   ID,
		   IsWorkshared,
		   ProjectID,
		   ShortFileName
		   
	FROM snapshot.ProjectFile
	
	WHERE (CompanyID = @CompanyiD)
	
	')


    PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectFile_Update'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_Update')
		DROP PROCEDURE [snapshot].ctcsp_ProjectFile_Update

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectFile_Update
	(
		@ID uniqueidentifier,
		@IsWorkshared bit,
		@ProjectID int,
		@ShortFileName nvarchar(255)
	)
	AS
		SET NOCOUNT ON;
		

		UPDATE [snapshot].[ProjectFile] SET 
			[IsWorkshared] = @IsWorkshared,
			[ProjectID] = @ProjectID,
			[ShortFileName] = @ShortFileName
			
		WHERE ([ID] = @ID);
		
		SELECT CentralOrSingleUserProjectFileName,
			   ID,
			   CompanyID,
			   IsWorkshared,
			   ProjectID,
			   ShortFileName
			   
		FROM ProjectFile 

		WHERE (ID = @ID)

	')

	
		
	-- ProjectFileSnapshot table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectFileSnapshot_ReadByProjectFileID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshot_ReadByProjectFileID')
		DROP PROCEDURE [snapshot].ctcsp_ProjectFileSnapshot_ReadByProjectFileID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectFileSnapshot_ReadByProjectFileID
	(
		@ProjectFileID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT	ID, 
			ProjectFileID, 
			SnapshotName,
			SnapshotDateAndTime, 
			SnapshotDateOnly,
			SnapshotTimeOnly,
			RecordedByUserName,
			FullFileName, 
			CentralOrSingleUserProjectFilePath,
			CentralOrSingleUserProjectShortFileName,
			FileSizeInBytes, 
			FileSizeInMegabytes,
			LastSaveTime, 
			LastSavedWithRevitVersion, 
			RecordedWithRevitVersion, 
			RecordedInRevitLanguageID, 
			RecordedInRevitLanguageName, 
			LastSavedWithRevitBuild, 
			RecordedWithRevitBuild, 
			SnapshotSettings, 
			SchemaVersionDuringSnapshot,
			SnapshotDurationInSeconds,
			ProcessingSeconds,
			LengthDisplayUnitType,
			ProjectAddress,
			ProjectStatus,
			ActiveViewName,
			StartingViewName,
			StandardViewsCount,
			SheetsCount,
			StandardViewsOnSheetsCount,
			StandardViewsNotOnSheetsCount,
			StandardViewsHealthScore,
			ViewTemplatesCount,
			ViewTemplatesUnusedCount,
			ViewTemplatesHealthScore,
			ViewFiltersCount,
			ViewFiltersUnusedCount,
			ViewFiltersHealthScore,
			ComponentFamiliesLoadedCount,
			ComponentFamiliesUnusedCount,
			ComponentFamilyTypesCount,
			ComponentFamilyTypesUnusedCount,
			ComponentFamilyInstanceCount,
			ComponentFamilyHealthScore,
			ComponentFamilyTypesHealthScore,
			ModelSystemFamilyTypesCount,
			ModelSystemFamilyTypesUnusedCount,
			ModelSystemFamilyInstanceCount,
			ModelSystemFamilyHealthScore,
			ViewportSystemFamilyTypesCount,
			ViewportSystemFamilyTypesUnusedCount,
			ViewportSystemFamilyTypesHealthScore,
			ColorFillLegendSystemFamilyTypesCount,
			ColorFillLegendSystemFamilyTypesUnusedCount,
			ColorFillLegendSystemFamilyTypesHealthScore,
			ColorFillSchemeSystemFamilyTypesCount,
			ColorFillSchemeSystemFamilyTypesUnusedCount,
			ColorFillSchemeSystemFamilyTypesHealthScore,
			TextSystemFamilyTypesCount,
			TextSystemFamilyTypesUnusedCount,
			TextSystemFamilyInstanceCount,
			TextSystemFamilyTypesHealthScore,
			DimensionSystemFamilyTypesCount,
			DimensionSystemFamilyTypesUnusedCount,
			DimensionSystemFamilyInstanceCount,
			DimensionSystemFamilyTypesHealthScore,
			MaterialTypesCount,
			MaterialTypesUnusedCount,
			MaterialTypesHealthScore,
			LineInstanceCount,
			LineStylesCount,
			LineStylesUnusedCount,
			LineStylesHealthScore,
			LinePatternsCount,
			LinePatternsUnusedCount,
			LinePatternsHealthScore,
			RevisionsCount,
			RevisionsUnusedCount,
			RevisionsHealthScore,
			ElementDefinitionCount,
			ElementInstanceCount,
			GroupTypesCount,
			GroupInstanceCount,
			WarningsCount,
			WarningsHealthScore,
			ScheduleCount,
			ProjectParameterCount,
			InvisibleProjectParameterCount,
			ProjectParameterHealthScore,
			UserWorksetCount,
			ImportsCount,
			LinksCount
			
	FROM snapshot.ProjectFileSnapshot 

	Where ProjectFileID = @ProjectFileID
	')

		
		
		
	-- ProjectInfoParameter table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectInfoParameter_ReadByProjectFileSnapshotID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectInfoParameter_ReadByProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_ProjectInfoParameter_ReadByProjectFileSnapshotID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectInfoParameter_ReadByProjectFileSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ElementID, 
			ProjectFileSnapshotID, 
			Name, 
			ParameterGroup, 
			ParameterType, 
			StorageType, 
			IsShared, 
			SharedParameterGUID, 
			HasValue, 
			IsReadOnly, 
			ValueAsElementID, 
			ValueAsString, 
			ValueInSystemUnits, 
			ValueInDisplayUnits, 
			DisplayUnitsSymbol,
			IsDisplayUnitsSymbolPrefixed
			
	FROM snapshot.ProjectInfoParameter 

	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID
	')

		
		
		
	-- ProjectParameterCategory table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectParameterCategory_ReadByProjectParameterDefinition'
		
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterCategory_ReadByProjectParameterDefinition')
		DROP PROCEDURE [snapshot].ctcsp_ProjectParameterCategory_ReadByProjectParameterDefinition

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectParameterCategory_ReadByProjectParameterDefinition
	(
		@ProjectParameterDefinitionID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;

	SELECT 	ID,
			ProjectParameterDefinitionID,
			ProjectFileSnapshotID, 
			CategoryName, 
			CategoryIsAnnotation 
			
	FROM snapshot.ProjectParameterCategory 

	WHERE ProjectParameterDefinitionID = @ProjectParameterDefinitionID 
	')

		
		
		
	-- ProjectParameterDefinition table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectParameterDefinition_ReadByProjectFileSnapshotID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterDefinition_ReadByProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_ProjectParameterDefinition_ReadByProjectFileSnapshotID

	EXEC('	
	CREATE PROCEDURE [snapshot].ctcsp_ProjectParameterDefinition_ReadByProjectFileSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ID,
			ProjectFileSnapshotID, 
			Name, 
			IsShared, 
			SharedParameterGUID, 
			ParameterGroup, 
			ParameterType, 
			IsInstance,
			IsVisible
			
	FROM snapshot.ProjectParameterDefinition 

	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID
	')



	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectParameterDefinition_ReadByID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectParameterDefinition_ReadByID')
		DROP PROCEDURE [snapshot].ctcsp_ProjectParameterDefinition_ReadByID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectParameterDefinition_ReadByID
	(
		@ID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ID,
			ProjectFileSnapshotID, 
			Name, 
			IsShared, 
			SharedParameterGUID, 
			ParameterGroup, 
			ParameterType, 
			IsInstance,
			IsVisible
			
	FROM snapshot.ProjectParameterDefinition 

	WHERE ID = @ID
	')

		
		
		
	-- ProjectUnusedItem table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ProjectUnusedItem_ReadByProjectFileSnapshotID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectUnusedItem_ReadByProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_ProjectUnusedItem_ReadByProjectFileSnapshotID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ProjectUnusedItem_ReadByProjectFileSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT ID, 
		   ProjectFileSnapshotID, 
		   ElementID, 
		   Category, 
		   ElementTypeName, 
		   Name
		   
	FROM snapshot.ProjectUnusedItem 

	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID
	')	
		
		
		
		
	-- Schedule table

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_Schedule_ReadByProjectFileSnapshotID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Schedule_ReadByProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_Schedule_ReadByProjectFileSnapshotID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_Schedule_ReadByProjectFileSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ID,
			ElementID, 
			ProjectFileSnapshotID, 
			Name, 
			CategoryName,
			HasEmbeddedSchedule, 
			IncludeLinkedFiles, 
			IsEmbedded, 
			IsKeySchedule, 
			IsItemized, 
			IsMaterialTakeOff, 
			IsInternalKeynoteSchedule, 
			IsTitleblockRevisionSchedule, 
			KeyScheduleParameterName, 
			FieldCount 
			
	FROM snapshot.Schedule 

	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID
	')
		
		
		
		
	-- ScheduleField table	
		
	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_ScheduleField_ReadByScheduleID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ScheduleField_ReadByScheduleID')
		DROP PROCEDURE [snapshot].ctcsp_ScheduleField_ReadByScheduleID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ScheduleField_ReadByScheduleID
	(
		@ScheduleID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;

	SELECT 	ID, 
			ScheduleID, 
			ElementID,
			ProjectFileSnapshotID, 
			ColumnHeading, 
			LocationIndex, 
			Name,
			ParameterType,
			IsCalculated, 
			IsHidden,
			CanTotal,
			TotalByAssemblyType,
			HasTotal,
			IsBuiltInParameter,
			IsSharedParameter,
			SharedParameterGUID
			
	FROM snapshot.ScheduleField 

	WHERE ScheduleID = @ScheduleID
	')	
		
		
		
		
	-- Warning table		

	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_Warning_ReadByProjectFileSnapshotID'
		
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Warning_ReadByProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_Warning_ReadByProjectFileSnapshotID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_Warning_ReadByProjectFileSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ID, 
			ProjectFileSnapshotID, 
			WorksetID, 
			WorksetName, 
			Severity, 
			DefinitionID, 
			Description, 
			ElementInstanceID, 
			ElementName,
			LevelElementInstanceID, 
			LevelName, 
			DefaultResolution 
			
	FROM snapshot.Warning 

	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID
	')	
		
		
		
		
	-- Workset table			
		
	PRINT 'Snapshot - Updating stored procedure for snapshot schema ctcsp_Workset_ReadByProjectFileSnapshotID'
		
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Workset_ReadByProjectFileSnapshotID')
		DROP PROCEDURE [snapshot].ctcsp_Workset_ReadByProjectFileSnapshotID

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_Workset_ReadByProjectFileSnapshotID
	(
		@ProjectFileSnapshotID uniqueidentifier
	)
	AS
		SET NOCOUNT ON;
		
	SELECT 	ID,
			ElementID, 
			ProjectFileSnapshotID, 
			Name, 
			WorksetKind, 
			Owner, 
			IsOpen, 
			IsDefault, 
			IsEditable, 
			IsVisibleByDefault 
			
	FROM snapshot.Workset 

	WHERE (ProjectFileSnapshotID = @ProjectFileSnapshotID)
	')
		
		
		
		
	-- Misc. Reporting Queries 


	PRINT 'Snapshot - Creating/updating reporting stored procedure for snapshot schema ctcsp_ElementInstance_ReadByProjectFileSnapshotID_Category'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_ReadByProjectFileSnapshotID_Category')
		DROP PROCEDURE [snapshot].ctcsp_ElementInstance_ReadByProjectFileSnapshotID_Category

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementInstance_ReadByProjectFileSnapshotID_Category
	(
		@ProjectFileSnapshotID uniqueidentifier,
		@CategoryName nvarchar(100)
	)
	AS
		SET NOCOUNT ON;
		
	SELECT        ID, ProjectFileSnapshotID, Name, CategoryName, CategoryIsAnnotation, CategoryIsInstanceCreatable, CategoryIsFamilyFileLoadable, IsSystemFamily, TypeCount, InstanceCount, ParameterValueCount
	FROM          snapshot.ElementDefinition
	WHERE        (ProjectFileSnapshotID = @ProjectFileSnapshotID) AND (CategoryName = @CategoryName)
	')



	PRINT 'Snapshot - Creating/updating reporting stored procedure for snapshot schema ctcsp_ElementInstance_ReadByProjectFileSnapshotID_Discipline'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstance_ReadByProjectFileSnapshotID_Discipline')
		DROP PROCEDURE [snapshot].ctcsp_ElementInstance_ReadByProjectFileSnapshotID_Discipline

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementInstance_ReadByProjectFileSnapshotID_Discipline
	(
		@ProjectFileSnapshotID uniqueidentifier,
		@DisciplineName nvarchar(50)
	)
	AS
		SET NOCOUNT ON;
		
	SELECT        ElementDefinition.ID, ElementDefinition.ProjectFileSnapshotID, ElementDefinition.Name, ElementDefinition.CategoryName, ElementDefinition.CategoryIsAnnotation, ElementDefinition.CategoryIsInstanceCreatable, 
							 ElementDefinition.CategoryIsFamilyFileLoadable, ElementDefinition.IsSystemFamily, ElementDefinition.TypeCount, ElementDefinition.InstanceCount, ElementDefinition.ParameterValueCount, 
							 Discipline.Name AS DisciplineName
	FROM          snapshot.ElementDefinition INNER JOIN
							 Discipline ON ElementDefinition.ID = Discipline.ElementDefinitionID AND ElementDefinition.ProjectFileSnapshotID = Discipline.ProjectFileSnapshotID
	WHERE        (ElementDefinition.ProjectFileSnapshotID = @ProjectFileSnapshotID) AND (Discipline.Name = @DisciplineName)
	')



	PRINT 'Snapshot - Creating/updating reporting stored procedure for snapshot schema ctcsp_ElementParameterValue_ReadByUniqueParameterName'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementParameterValue_ReadByUniqueParameterName')
		DROP PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadByUniqueParameterName

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadByUniqueParameterName
	(
		@ProjectFileSnapshotID uniqueidentifier,
		@ParameterName nvarchar(255)
	)
	AS
		SET NOCOUNT ON;
		
	SELECT DISTINCT ValueAsString, count(ValueAsString) as CountOf 
	FROM snapshot.ElementParameterValue
	WHERE ProjectFileSnapshotID = @ProjectFileSnapshotID AND ParameterName = @ParameterName
	GROUP BY ValueAsString
	')



	PRINT 'Snapshot - Creating/updating reporting stored procedure for snapshot schema ctcsp_ElementParameterValue_ReadByUniqueParameterNameForCategory'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementParameterValue_ReadByUniqueParameterNameForCategory')
		DROP PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadByUniqueParameterNameForCategory

	EXEC('
	CREATE PROCEDURE [snapshot].ctcsp_ElementParameterValue_ReadByUniqueParameterNameForCategory
	(
		@ProjectFileSnapshotID uniqueidentifier,
		@ParameterName nvarchar(255),
		@CategoryName nvarchar(100)
	)
	AS
		SET NOCOUNT ON;

	SELECT DISTINCT ElementParameterValue.ValueAsString, COUNT(ElementParameterValue.ValueAsString) AS CountOf
	FROM             snapshot.ElementDefinition INNER JOIN
							  ElementParameterValue  ON ElementDefinition.ID = ElementParameterValue.ElementDefinitionID  AND ElementDefinition.ProjectFileSnapshotID = ElementParameterValue.ProjectFileSnapshotID
	WHERE        (ElementDefinition .ProjectFileSnapshotID = @ProjectFileSnapshotID) AND (ElementParameterValue.ParameterName = @ParameterName)
	GROUP BY ElementParameterValue.ValueAsString, ElementDefinition.CategoryName
	HAVING        (ElementDefinition.CategoryName = @CategoryName)
	')

	
	
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_AutoFixIncorrectProjectIds'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_AutoFixIncorrectProjectIds' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_AutoFixIncorrectProjectIds] 
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_AutoFixIncorrectProjectIds]
		(
			@p_CompanyID int
		)
		AS
			SET NOCOUNT OFF;
		
			UPDATE  snapshot.ProjectFile
			SET     ProjectID = pp.ProjectID
			FROM    snapshot.ProjectFile As pf
			INNER JOIN asset.ProjectPath AS pp
				ON LEFT
				(pf.CentralOrSingleUserProjectFileName, LEN(pf.CentralOrSingleUserProjectFileName) - CHARINDEX(''\'', 
								 REVERSE(pf.CentralOrSingleUserProjectFileName), 1)) = pp.CentralFilePath COLLATE SQL_Latin1_General_CP1_CI_AS
			
			WHERE (pf.CompanyID = @p_CompanyID)
			AND (pf.ProjectID <> pp.ProjectID); ');

			
			
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_AutoFixUnassignedProjectIds'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_AutoFixUnassignedProjectIds' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_AutoFixUnassignedProjectIds] 
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_AutoFixUnassignedProjectIds]
		(
			@p_CompanyID int
		)
		AS
			SET NOCOUNT OFF;
		
			UPDATE ProjectFile
			  SET ProjectFile.ProjectID = pp.ProjectID
			  FROM snapshot.ProjectFile AS pf
			  INNER JOIN asset.ProjectPath AS pp
			  ON LEFT(pf.CentralOrSingleUserProjectFileName, 
				LEN(pf.CentralOrSingleUserProjectFileName) - CHARINDEX(''\'', REVERSE(pf.CentralOrSingleUserProjectFileName),
				 1)) = pp.CentralFilePath COLLATE SQL_Latin1_General_CP1_CI_AS
			  WHERE (pf.CompanyID = @p_CompanyID)
			  AND   (pf.ProjectID IS NULL); ');

			  
			  
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_ReadByCentralOrSingleUserProjectFileName'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadByCentralOrSingleUserProjectFileName' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadByCentralOrSingleUserProjectFileName] 
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadByCentralOrSingleUserProjectFileName]
		(
			@p_CompanyID int,
			@CentralOrSingleUserProjectFileName nvarchar(255)
		)
		AS
			SET NOCOUNT ON;
		
		SELECT CentralOrSingleUserProjectFileName, 
				pf.ID, 
				pf.IsWorkshared, 
				pf.ProjectID, 
				pf.ShortFileName
		FROM    snapshot.ProjectFile As pf 
		WHERE (pf.CompanyID = @p_CompanyID)
		AND   (CentralOrSingleUserProjectFileName = @CentralOrSingleUserProjectFileName) ');

		
		
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_ReadByProjectID'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadByProjectID' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadByProjectID] 
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadByProjectID]
		(
			@ProjectID int
		)
		AS
			SET NOCOUNT ON;
		
		SELECT ID,
			   CentralOrSingleUserProjectFileName,
			   CompanyID,
			   ProjectID,
			   IsWorkshared,
			   ShortFileName
		   
		FROM snapshot.ProjectFile

		WHERE (ProjectID = @ProjectID) ');

		
		
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_ReadMappedProjectPaths'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadMappedProjectPaths' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadMappedProjectPaths]
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadMappedProjectPaths] 
		(
			@p_CompanyID int
		)
			AS
			BEGIN
				-- SET NOCOUNT ON is added to prevent extra result sets from
				-- interfering with SELECT statements.
				SET NOCOUNT ON;

				SELECT DISTINCT
					convert(nvarchar(40), pp.ID) AS ID
					,LEFT(pf.CentralOrSingleUserProjectFileName,LEN(pf.CentralOrSingleUserProjectFileName) - charindex(''\'',reverse(pf.CentralOrSingleUserProjectFileName),1)) As CentralOrSingleUserProjectFileName
					,pr.ProjectNumber AS DocProjectNumber
					,pr.ID AS DocProjectID
				FROM snapshot.ProjectFile as pf
					LEFT OUTER JOIN asset.Project AS pr 
					INNER JOIN asset.ProjectPath AS pp ON pr.ID = pp.ProjectID 
					ON LEFT(pf.CentralOrSingleUserProjectFileName,LEN(pf.CentralOrSingleUserProjectFileName) - charindex(''\'',reverse(pf.CentralOrSingleUserProjectFileName),1)) = pp.CentralFilePath  COLLATE SQL_Latin1_General_CP1_CI_AS
				WHERE (pf.CompanyID = @p_CompanyID)
				AND (pp.ProjectID IS NOT NULL)
				ORDER BY DocProjectNumber, CentralOrSingleUserProjectFileName

			END ');

			
			
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_ReadWithDeletedProjectIds'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadWithDeletedProjectIds' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithDeletedProjectIds]
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithDeletedProjectIds] 
		(
			@p_CompanyID int
		)
		AS
		BEGIN
			-- SET NOCOUNT ON is added to prevent extra result sets from
			-- interfering with SELECT statements.
			SET NOCOUNT ON;

		SELECT 
			pf.ID,
			pf.CentralOrSingleUserProjectFileName, 
			pf.ShortFileName,
			pf.ProjectID AS DocProjectID,
			''deleted'' AS DocProjectNumber,
			pp.ProjectID AS ProjProjectID, 
			p1.ProjectNumber AS ProjProjectNumber,
			pp.AddedDate AS ProjDateTime
		FROM snapshot.ProjectFile As pf
		LEFT JOIN asset.Project As pr ON pr.ID = pf.ProjectID 
		INNER JOIN
			asset.ProjectPath As pp ON LEFT(pf.CentralOrSingleUserProjectFileName, LEN(pf.CentralOrSingleUserProjectFileName) - CHARINDEX(''\'', REVERSE(pf.CentralOrSingleUserProjectFileName), 1)) = pp.CentralFilePath COLLATE SQL_Latin1_General_CP1_CI_AS
		INNER JOIN asset.Project AS p1 ON pp.ProjectID = p1.ID 
		WHERE (pf.CompanyID = @p_CompanyID)
		AND   (pr.ID IS NULL)
		ORDER BY CentralOrSingleUserProjectFileName, DocProjectID, ProjDateTime 

		END ');

		
		
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_ReadWithNoProject'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadWithNoProject' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithNoProject]
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithNoProject] 
		(
			@p_CompanyID int
		)	
		AS
		BEGIN
			-- SET NOCOUNT ON is added to prevent extra result sets from
			-- interfering with SELECT statements.
			SET NOCOUNT ON;

		SELECT DISTINCT
			Left(pf.CentralOrSingleUserProjectFileName,LEN(pf.CentralOrSingleUserProjectFileName) 
			- charindex(''\'',reverse(pf.CentralOrSingleUserProjectFileName),1)) 
			As CentralOrSingleUserProjectFileName
		FROM snapshot.ProjectFile As pf
			LEFT OUTER JOIN asset.Project AS p1
			INNER JOIN asset.ProjectPath As pp ON p1.ID = pp.ProjectID 
			ON LEFT(pf.CentralOrSingleUserProjectFileName,LEN(pf.CentralOrSingleUserProjectFileName) 
			- charindex(''\'',reverse(pf.CentralOrSingleUserProjectFileName),1)) = pp.CentralFilePath COLLATE SQL_Latin1_General_CP1_CI_AS
			AND pf.ProjectID <> pp.ProjectID
		WHERE (pf.CompanyID = @p_CompanyID)
		AND (pf.ProjectID IS NULL) 
		AND (pp.ProjectID IS NULL)
		ORDER BY CentralOrSingleUserProjectFileName

		END ');

		
		
	PRINT 'Snapshot - Creating cctcsp_ProjectFile_ReadWithUnassignedProjectIds'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadWithUnassignedProjectIds' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithUnassignedProjectIds]
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithUnassignedProjectIds] 
		(
			@p_CompanyID int
		)	
		AS
		BEGIN
			SET NOCOUNT ON;

		SELECT  
			pf.ID,       
			pf.CentralOrSingleUserProjectFileName, 
			pf.ShortFileName, 
			pf.ProjectID AS DocProjectID, 
			p2.ProjectNumber AS DocProjectNumber, 
			pp.ProjectID AS ProjProjectID, 
			p1.ProjectNumber AS ProjProjectNumber, 
			pp.AddedDate AS ProjDateTime
		FROM snapshot.ProjectFile As pf
			INNER JOIN
				asset.ProjectPath As pp ON 
				LEFT(pf.CentralOrSingleUserProjectFileName,LEN(pf.CentralOrSingleUserProjectFileName) - charindex(''\'',reverse(pf.CentralOrSingleUserProjectFileName),1)) = pp.CentralFilePath COLLATE SQL_Latin1_General_CP1_CI_AS
				AND pf.ProjectID <> pp.ProjectID

			INNER JOIN asset.Project AS p1 ON pp.ProjectID = p1.ID 
			INNER JOIN asset.Project As p2 ON pf.ProjectID = p2.ID
		WHERE (pf.CompanyID = @p_CompanyID)
		AND   (pf.ProjectID IS NULL)
		ORDER BY CentralOrSingleUserProjectFileName, DocProjectID, ProjDateTime
		END ');

		
		
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_ReadWithUnmatchedProjectIds'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadWithUnmatchedProjectIds' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithUnmatchedProjectIds]
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithUnmatchedProjectIds] 
		(
			@p_CompanyID int
		)	
		AS
		BEGIN
			-- SET NOCOUNT ON is added to prevent extra result sets from
			-- interfering with SELECT statements.
			SET NOCOUNT ON;

			SELECT        
				pf.ID,
				pf.CentralOrSingleUserProjectFileName,
				pf.ShortFileName, 
				pf.ProjectID AS DocProjectID, 
				p2.ProjectNumber AS DocProjectNumber, 
				pp.ProjectID AS ProjProjectID, 
				p1.ProjectNumber AS ProjProjectNumber,
				pp.AddedDate AS ProjDateTime
			FROM snapshot.ProjectFile as pf
				INNER JOIN
					asset.ProjectPath pp
					ON LEFT(pf.CentralOrSingleUserProjectFileName,LEN(pf.CentralOrSingleUserProjectFileName) - charindex(''\'',reverse(pf.CentralOrSingleUserProjectFileName),1)) = pp.CentralFilePath COLLATE SQL_Latin1_General_CP1_CI_AS
					AND pf.ProjectID <> pp.ProjectID
				INNER JOIN asset.Project AS p1 ON pp.ProjectID = p1.ID 
				INNER JOIN asset.Project AS p2 ON pf.ProjectID = p2.ID
			WHERE (pf.CompanyID = @p_CompanyID)
			AND   (pf.ProjectID IS NOT NULL)
			ORDER BY CentralOrSingleUserProjectFileName, DocProjectID,ProjDateTime
		END ');

		
		
	PRINT 'Snapshot - Creating ctcsp_ProjectFileSnapshot_ReadByProjectFileID'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshot_ReadByProjectFileID' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFileSnapshot_ReadByProjectFileID]
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFileSnapshot_ReadByProjectFileID]
		(
			@ProjectFileID uniqueidentifier
		)
		AS
			SET NOCOUNT ON;
		
		SELECT	ID, 
				CompanyID,
				ProjectFileID, 
				SnapshotName,
				SnapshotDateAndTime, 
				SnapshotDateOnly,
				SnapshotTimeOnly,
				RecordedByUserName,
				FullFileName, 
				CentralOrSingleUserProjectFilePath,
				CentralOrSingleUserProjectShortFileName,
				FileSizeInBytes, 
				FileSizeInMegabytes,
				LastSaveTime, 
				LastSavedWithRevitVersion, 
				RecordedWithRevitVersion, 
				RecordedInRevitLanguageID, 
				RecordedInRevitLanguageName, 
				LastSavedWithRevitBuild, 
				RecordedWithRevitBuild, 
				SnapshotSettings, 
				SchemaVersionDuringSnapshot,
				SnapshotDurationInSeconds,
				ProcessingSeconds,
				LengthDisplayUnitType,
				ProjectAddress,
				ProjectStatus,
				ActiveViewName,
				StartingViewName,
				StandardViewsCount,
				SheetsCount,
				StandardViewsOnSheetsCount,
				StandardViewsNotOnSheetsCount,
				StandardViewsHealthScore,
				ViewTemplatesCount,
				ViewTemplatesUnusedCount,
				ViewTemplatesHealthScore,
				ViewFiltersCount,
				ViewFiltersUnusedCount,
				ViewFiltersHealthScore,
				ComponentFamiliesLoadedCount,
				ComponentFamiliesUnusedCount,
				ComponentFamilyTypesCount,
				ComponentFamilyTypesUnusedCount,
				ComponentFamilyInstanceCount,
				ComponentFamilyHealthScore,
				ComponentFamilyTypesHealthScore,
				ModelSystemFamilyTypesCount,
				ModelSystemFamilyTypesUnusedCount,
				ModelSystemFamilyInstanceCount,
				ModelSystemFamilyHealthScore,
				ViewportSystemFamilyTypesCount,
				ViewportSystemFamilyTypesUnusedCount,
				ViewportSystemFamilyTypesHealthScore,
				ColorFillLegendSystemFamilyTypesCount,
				ColorFillLegendSystemFamilyTypesUnusedCount,
				ColorFillLegendSystemFamilyTypesHealthScore,
				ColorFillSchemeSystemFamilyTypesCount,
				ColorFillSchemeSystemFamilyTypesUnusedCount,
				ColorFillSchemeSystemFamilyTypesHealthScore,
				TextSystemFamilyTypesCount,
				TextSystemFamilyTypesUnusedCount,
				TextSystemFamilyInstanceCount,
				TextSystemFamilyTypesHealthScore,
				DimensionSystemFamilyTypesCount,
				DimensionSystemFamilyTypesUnusedCount,
				DimensionSystemFamilyInstanceCount,
				DimensionSystemFamilyTypesHealthScore,
				MaterialTypesCount,
				MaterialTypesUnusedCount,
				MaterialTypesHealthScore,
				LineInstanceCount,
				LineStylesCount,
				LineStylesUnusedCount,
				LineStylesHealthScore,
				LinePatternsCount,
				LinePatternsUnusedCount,
				LinePatternsHealthScore,
				RevisionsCount,
				RevisionsUnusedCount,
				RevisionsHealthScore,
				ElementDefinitionCount,
				ElementInstanceCount,
				GroupTypesCount,
				GroupInstanceCount,
				WarningsCount,
				WarningsHealthScore,
				ScheduleCount,
				ProjectParameterCount,
				InvisibleProjectParameterCount,
				ProjectParameterHealthScore,
				UserWorksetCount,
				ImportsCount,
				LinksCount
			
		FROM ProjectFileSnapshot 

		Where ProjectFileID = @ProjectFileID ');

	
	
	END   -- Must update SNAPSHOT stored procedures  from schema version 3 to 4 '

	IF @palvers = 3 
	BEGIN

	--------------------------------------------------------------------------------
	--PRINT 'Rename Columns to ASSET Tables'
	--------------------------------------------------------------------------------
	
	--EXEC sp_rename 'asset.Project.ProjectStatus', 'ProjectPhase', 'COLUMN';  
		
	--------------------------------------------------------------------------------
	--PRINT 'Adding Columns to PAL Tables'
	--------------------------------------------------------------------------------
	IF NOT EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[pal].[LogDocSession]') 
					AND name = 'WorksetOpenCt'
		)
		BEGIN
			PRINT 'PAL - Adding WorksetOpenCt to LogDocSession'
			ALTER TABLE pal.LogDocSession
			ADD WorksetOpenCt [int] NOT NULL DEFAULT 1
		END
			
		IF NOT EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[pal].[LogDocSession]') 
					AND name = 'WorksetEditCt'
		)
		BEGIN
			PRINT 'PAL - Adding WorksetEditCt to LogDocSession'
			ALTER TABLE pal.LogDocSession
			ADD WorksetEditCt [int] NOT NULL DEFAULT 1
		END
		
		IF NOT EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[pal].[LogDocSession]') 
					AND name = 'SiteLatLong'
		)
		BEGIN
			PRINT 'PAL - Adding SiteLatLong to LogDocSession'
			ALTER TABLE pal.LogDocSession
			ADD SiteLatLong [NVARCHAR](50) NULL
		END

		IF NOT EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[pal].[LogSummary]') 
					AND name = 'WarningsCt'
		)
		BEGIN
			PRINT 'PAL - Adding WarningCt to LogSummary'
			ALTER TABLE pal.LogSummary
			ADD WarningCt [int] NOT NULL DEFAULT 1
		END

		IF NOT EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[pal].[LogDocumentProjChange]') 
					AND name = 'OldProjID'
		)
		BEGIN
			PRINT 'PAL - Adding OldProjID to LogDocumentProjChange'
			ALTER TABLE pal.LogDocumentProjChange
			ADD OldProjID [int] NOT NULL DEFAULT 0
		END

		IF NOT EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[pal].[LogDocumentProjChange]') 
					AND name = 'NewProjID'
		)
		BEGIN
			PRINT 'PAL - Adding NewProjID to LogDocumentProjChange'
			ALTER TABLE pal.LogDocumentProjChange
			ADD NewProjID [int] NOT NULL DEFAULT 0
		END

		IF NOT EXISTS (
			SELECT * 
			FROM   sys.columns 
			WHERE  object_id = OBJECT_ID(N'[asset].[ProjectPath]') 
					AND name = 'AddedByUserID'
		)
		BEGIN
			PRINT 'PAL - Adding AddedByUserID to ProjectPath'
			ALTER TABLE asset.ProjectPath
			ADD AddedByUserID [int] NOT NULL DEFAULT 0
		END
		
	--------------------------------------------------------------------------------
	PRINT 'Dropping Columns to PAL Tables'
	--------------------------------------------------------------------------------
		
		PRINT 'PAL - Drop UserName from ProjectPath'
		ALTER TABLE asset.ProjectPath DROP COLUMN UserName
		
		PRINT 'PAL - Drop CheckVal from LogWarning'
		ALTER TABLE pal.LogWarning DROP COLUMN CheckVal
		
		PRINT 'PAL - Drop CheckVal from LogViewType'
		ALTER TABLE pal.LogViewType DROP COLUMN CheckVal
		
		PRINT 'PAL - Drop CheckVal from LogLink'
		ALTER TABLE pal.LogLink DROP COLUMN CheckVal
		
		PRINT 'PAL - LogDocumentProjChange ALTER COLUMN OldProjID [INT] NULL'
		ALTER TABLE pal.LogDocumentProjChange ALTER COLUMN OldProjID [INT] NULL;
	
	
    --------------------------------------------------------------------------------
	PRINT 'PAL - Creating LogSetting table'
	--------------------------------------------------------------------------------
	IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'LogSetting')
		BEGIN
			CREATE TABLE [pal].[LogSetting](
						[ID] [int] IDENTITY(1,1) NOT NULL,
						[CompanyID] [int] NOT NULL,
						[LogWarningsForPre2018] [bit] NOT NULL,
						[LogDetailedWarnings] [bit] NOT NULL,
						[LogSummarizedWarnings] [bit] NOT NULL,
						[LogDetailedElementChanges] [bit] NOT NULL,
						[LogAddIns] [bit] NOT NULL,
						[LogPrinting] [bit] NOT NULL,
						[LogViewChange] [bit] NOT NULL,
						[LogAuditFlag] [bit] NOT NULL,
						[LogNonWorkshared] [bit] NOT NULL,
						[InferProject] [bit] NOT NULL,
						[AddedDate] [datetime] NOT NULL,
						[AddedByUserID] [int] NOT NULL,
						[UpdatedDate] [datetime] NOT NULL,
						[UpdatedByUserID] [int] NOT NULL,
					 CONSTRAINT [PK_pal.LogSetting] PRIMARY KEY CLUSTERED 
			(
				[ID] ASC
			)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
			) ON [PRIMARY]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_LogWarningsForPre2018]  DEFAULT ((0)) FOR [LogWarningsForPre2018]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_LogDetailedWarnings]  DEFAULT ((0)) FOR [LogDetailedWarnings]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_LogDetailedElementChanges]  DEFAULT ((0)) FOR [LogDetailedElementChanges]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_LogAddIns]  DEFAULT ((0)) FOR [LogAddIns]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_LogPrinting]  DEFAULT ((0)) FOR [LogPrinting]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_LogViewChange]  DEFAULT ((0)) FOR [LogViewChange]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_LogAuditFlag]  DEFAULT ((0)) FOR [LogAuditFlag]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_LogNonWorkshared]  DEFAULT ((0)) FOR [LogNonWorkshared]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_InferProject]  DEFAULT ((0)) FOR [InferProject]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_AddedByUserID]  DEFAULT ((0)) FOR [AddedByUserID]
			ALTER TABLE [pal].[LogSetting] ADD  CONSTRAINT [DF_LogSetting_UpdatedByUserID]  DEFAULT ((0)) FOR [UpdatedByUserID]
			
		IF @palvers <= 4
		BEGIN
			PRINT 'PAL - Adding initial data to LogSetting table for CompanyID = 1'
			SET IDENTITY_INSERT pal.LogSetting ON;
			DECLARE @Settings nvarchar(2000);
			SET @Settings = '
			INSERT INTO pal.LogSetting(
					[ID]
					,[CompanyID]
					,[LogWarningsForPre2018]
					,[LogDetailedWarnings]
					,[LogSummarizedWarnings]
					,[LogDetailedElementChanges]
					,[LogAddIns]
					,[LogPrinting]
					,[LogViewChange]
					,[LogAuditFlag]
					,[LogNonWorkshared]
					,[InferProject]
					,[AddedDate]
					,[AddedByUserID]
					,[UpdatedDate]
					,[UpdatedByUserID])
					VALUES(
					0
					,1
					,1
					,1
					,1
					,1
					,1
					,1
					,1
					,1
					,0
					,0
					,GETUTCDATE()
					,0
					,GETUTCDATE()
					,0);

			EXEC(@Settings);	 
			SET IDENTITY_INSERT pal.LogSetting OFF;'

		END
	END;
	
	PRINT ''
	PRINT 'PAL - Creating table LogPrint'
	IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'LogPrint')
	BEGIN
		CREATE TABLE [pal].[LogPrint](
			[ID] [int] IDENTITY(1,1) NOT NULL,
			[DocSessionID] [int] NOT NULL,
			[JobID] [int] NOT NULL,
			[UserName] [nvarchar](100) NOT NULL,
			[Printed] [nvarchar](MAX) NOT NULL,
			[Failed] [nvarchar](MAX) NOT NULL,
			[PrintCt] [int] NOT NULL,
			[FailCt] [int] NOT NULL,
			[JobStart] [datetime] NOT NULL,
			[JobEnd] [datetime] NOT NULL,
		 CONSTRAINT [PK_dbo.LogPrint] PRIMARY KEY CLUSTERED 
		 (
			[ID] ASC
		 )
		 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
			   ) ON [PRIMARY] 
		
		ALTER TABLE [pal].[LogPrint]  WITH CHECK ADD  CONSTRAINT [FK_pal.LogPrint_pal.LogDocument_DocSessionID] FOREIGN KEY([DocSessionID])
		REFERENCES [pal].[LogDocSession] ([ID])
		ON UPDATE CASCADE
		ON DELETE CASCADE
		ALTER TABLE [pal].[LogPrint] CHECK CONSTRAINT [FK_pal.LogPrint_pal.LogDocument_DocSessionID]
	END;
	
	PRINT 'PAL - Creating table LogENUM'
	IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'LogENUM')
	BEGIN
		CREATE TABLE [pal].[LogENUM](
			[ID] [int] IDENTITY(1,1) NOT NULL,
			[EnumType] [nvarchar](50) NOT NULL,
			[EnumID] [int] NOT NULL,
			[Description] [nvarchar](50) NOT NULL
			CONSTRAINT [PK_dbo.LogENUM] PRIMARY KEY CLUSTERED 
			(
			[ID] ASC
			)
			WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
				) ON [PRIMARY] 

			INSERT INTO pal.LogENUM([EnumType],[EnumID],[Description])
				VALUES(
				'ElementChange'
				,0
				,'Added');
			INSERT INTO pal.LogENUM([EnumType],[EnumID],[Description])
				VALUES(
				'ElementChange'
				,1
				,'Deleted');
			INSERT INTO pal.LogENUM([EnumType],[EnumID],[Description])
				VALUES(
				'ElementChange'
				,2
				,'Modified');

	END;
		
	PRINT ''
	PRINT 'PAL - Creating table LogWarningSummary'
	IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'LogWarningSummary')
	BEGIN
		CREATE TABLE [pal].[LogWarningSummary](
			[ID] [int] IDENTITY(1,1) NOT NULL,
			[DocSessionID] [int] NOT NULL,
			[ElementIds] [NVARCHAR](MAX) NOT NULL,
			[Description] [VARCHAR](255) NOT NULL,
			[LogDateTime] [datetime] NOT NULL
		 CONSTRAINT [PK_dbo.LogWarningSummary] PRIMARY KEY CLUSTERED 
		 (
			[ID] ASC
		 )
		 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
			   ) ON [PRIMARY] 
		
		ALTER TABLE [pal].[LogWarningSummary]  WITH CHECK ADD  CONSTRAINT [FK_pal.LogWarningSummary_pal.LogDocument_DocSessionID] FOREIGN KEY([DocSessionID])
		REFERENCES [pal].[LogDocSession] ([ID])
		ON UPDATE CASCADE
		ON DELETE CASCADE
		ALTER TABLE [pal].[LogWarningSummary] CHECK CONSTRAINT [FK_pal.LogWarningSummary_pal.LogDocument_DocSessionID]
	END;
		
	PRINT ''
	PRINT 'PAL - Creating table LogSession'
	IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'LogSession')
	BEGIN	
		CREATE TABLE [pal].[LogSession](
			[ID] [uniqueidentifier] NOT NULL,
			[CompanyID] [int] NOT NULL,
			[UserName] [nvarchar](100) NOT NULL,
			[RevitVersion] [int] NULL,
			[MachineName] [nvarchar](255) NULL,
			[StartDateTime] [datetime] NOT NULL,
			[EndDateTime] [datetime] NULL,
		 CONSTRAINT [PK_LogSession] PRIMARY KEY CLUSTERED 
		(
			[ID] ASC
		)
		WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
		) ON [PRIMARY]

		ALTER TABLE [pal].[LogSession] ADD  CONSTRAINT [DF_LogSession_ID]  DEFAULT (newid()) FOR [ID]
		
		ALTER TABLE [pal].[LogSession] ADD  DEFAULT ((1)) FOR [CompanyID]
		
	END;
	--------------------------------------------------------------------------------
	PRINT 'Upgrading PAL Views to new int IDs'
	--------------------------------------------------------------------------------
	
	PRINT ''
	PRINT 'PAL - Updating ctcvw_Projects'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Projects' )
			DROP VIEW  pal.ctcvw_Projects
		EXEC('CREATE VIEW [pal].[ctcvw_Projects]
		AS
		SELECT  TOP 100 PERCENT
				ID As Id, 
				ProjectNumber + N'' - '' + ProjectName AS Project, 
				ProjectNumber AS [Project Number], 
				ProjectName AS [Project Name], 
				ClientName AS [Client Name] 
				,[ProjectPhase]
				,ProjectIssueDate AS [Issue Date]
				,DATEDIFF(DAY, { fn NOW() }, ProjectIssueDate) AS [Days Until Issue]
				,[Office]
				,[ClientName]
				,[OrgDescription]
				,[OrgName]
				,[Author]
				,[BuildingName]
				,[StreetAddress]
				,[StreetAddress2]
				,[StreetAddress3]
				,[City]
				,[StateOrProvince]
				,[PostalCode]
				,[CountryName]
				,[AddedDate]
				,[UpdatedDate]
				,[CompanyID]
		FROM    asset.Project
		WHERE   (ID <> 0)
		ORDER BY [Issue Date] ')


	PRINT 'PAL - Updating ctcvw_Sessions_LastSTC'	
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Sessions_LastSTC' )
			DROP VIEW  pal.ctcvw_Sessions_LastSTC
		EXEC('CREATE VIEW [pal].[ctcvw_Sessions_LastSTC]
		AS
		SELECT  DocSessionID As DocSessionId,  
				EventId, 
				EventDuration, 
				EventDateTime
		FROM    pal.LogEvent as Data
		WHERE  (EventDateTime =
					(SELECT MAX(EventDateTime) AS Expr1
						FROM pal.LogEvent
							WHERE (EventName = N''SyncComplete'')
							AND (DocSessionID = Data.DocSessionID))) ')

	PRINT 'PAL - Updating ctcvw_Sessions_LastEvent'	
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Sessions_LastEvent' )
			DROP VIEW  pal.ctcvw_Sessions_LastEvent
		EXEC('CREATE VIEW [pal].[ctcvw_Sessions_LastEvent]
		AS
		SELECT  DocSessionID, 
				MAX(EventDateTime) AS EventDateTime
		FROM    pal.LogEvent
		GROUP BY DocSessionID ')
				
	PRINT 'PAL - Updating ctcvw_Sessions_LastSummary'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Sessions_LastSummary' )
		DROP VIEW  pal.ctcvw_Sessions_LastSummary
		EXEC('CREATE VIEW [pal].[ctcvw_Sessions_LastSummary]
		AS
		SELECT  DocSessionID As DocSessionId, 
				EventId, 
				GroupCt, 
				InPlaceCt, 
				UnPlacedRoomCt, 
				UnenclosedRoomCt, 
				PlacedRoomCt, 
				UnPlacedSpaceCt, 
				UnenclosedSpaceCt,
				PlacedSpaceCt, 
				ViewCt, 
				PhaseCt, 
				DesOptCt, 
				WorksetCt, 
				FamilyCt, 
				InstanceCt, 
				UnplacedFamilyCt, 
				MaterialCt, 
				ViewFilterCt, 
				SummaryDateTime, 
				LevelCt,
				WarningCt
		FROM    pal.LogSummary AS Data
		WHERE  (SummaryDateTime =
				(SELECT MAX(SummaryDateTime) AS Expr1
					FROM pal.LogSummary
					WHERE (DocSessionID = Data.DocSessionID))) ')

	PRINT 'PAL - Updating ctcvw_Warnings_Total'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Warnings_Total' )
		DROP VIEW  pal.ctcvw_Warnings_Total
		EXEC('CREATE VIEW [pal].[ctcvw_Warnings_Total]
		AS
		SELECT   DocSessionID As DocSessionId, 
					COUNT(ElementId) AS Warnings
		FROM     pal.LogWarning
		GROUP BY DocSessionID ')

	PRINT 'PAL - Updating ctcvw_Sessions'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Sessions' )
		DROP VIEW  pal.ctcvw_Sessions
		EXEC('CREATE VIEW [pal].[ctcvw_Sessions]
		AS
		SELECT  Data.ID As Id, 
				Data.CompanyID, 
				Data.ProjectID As ProjectId, 
				ISNULL(Project.ProjectNumber, ''Unassigned'') AS [Project Number], 
				ISNULL(Project.ProjectName, ''unknown'') AS [Project Name], 
				ISNULL(Project.ClientName, ''unknown'') AS [Client Name], 
				Data.UserName AS Contributor, 
				Data.MachineName, 
				Data.Server, 
				Data.CentralFileName AS [Central File], 
				Data.ShortFileName AS [File Name], 
				Data.LocalFileName AS [Local File], 
				Data.LocalFileSize / 1048576.0 AS [File Size (MB)], 
				Data.RevitVersion AS [Revit Version], 
				Data.IsAudit AS Auditing, 
				Data.DocDateTime AS Opened,
				Data.STCDateTime AS [Last Saved], 
				Data.LoadTime AS [Open Duration (Sec)], 
				Data.STCDuration AS [STC Duration (Sec)], 
				Data.SessionHours AS [Session Hours], 
				Data.GroupCt AS Groups, 
				Data.InPlaceCt AS [In-place Families], 
				Data.UnPlacedRoomCt AS [Unplaced Rooms], 
				Data.UnenclosedRoomCt AS [Unenclosed Rooms], 
				Data.PlacedRoomCt AS Rooms, 
				Data.UnPlacedSpaceCt AS [Unplaced Spaces], 
				Data.UnenclosedSpaceCt As [Unenclosed Spaces], 
				Data.PlacedSpaceCt As Spaces,
				Data.ViewCt AS Views, 
				Data.PhaseCt AS Phases, 
				Data.DesOptCt AS [Design Options], 
				Data.WorksetCt AS Worksets, 
				Data.WorksetEditCt AS EditableWorksets,
				Data.WorksetOpenCt AS OpenWorksets, 
				Data.FamilyCt AS Families, 
				Data.InstanceCt AS [Family Instances], 
				Data.UnplacedFamilyCt AS [Unplaced Families], 
				Data.MaterialCt AS Materials, 
				Data.ViewFilterCt AS [View Filters], 
				Data.LevelCt AS Levels, 
				Data.ElemAddedCt AS Added, 
				Data.ElemDeletedCt AS Deleted, 
				Data.ElemModifiedCt AS Modified, 
				ISNULL(Data.ElemAddedCt + Data.ElemDeletedCt + Data.ElemModifiedCt, 0) 
									AS [Edited Items], 
				Data.WarningCt AS Warnings, 
				CONVERT(DateTime, CONVERT(Date, Data.DocDateTime, 101)) AS DayOpened, 
				Data.HasClosed,
				Data.BasePoint,
				Data.SurveyPoint,
				Data.AngleToTrueNorth,
				Data.SiteLatLong,
				pal.ctcvw_Sessions_LastEvent.EventDateTime AS [Last Action]
			FROM pal.LogDocSession AS Data 
			--LEFT OUTER JOIN asset.Project ON Data.ProjectID = asset.Project.ID 
			INNER JOIN asset.Project ON Data.ProjectID = asset.Project.ID 
			INNER JOIN pal.ctcvw_Sessions_LastEvent ON Data.ID = pal.ctcvw_Sessions_LastEvent.DocSessionID')

	PRINT 'PAL - Updating ctcvw_CentralFiles'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_CentralFiles' )
		DROP VIEW  pal.ctcvw_CentralFiles
		EXEC('CREATE VIEW [pal].[ctcvw_CentralFiles]
		AS
		SELECT  Id, 
				ProjectId, 
				[Project Number], 
				[Project Name], 
				[Client Name], 
				Contributor, 
				Server, 
				[Central File], 
				[File Name], 
				[Local File], 
				[File Size (MB)], 
				[Revit Version], 
				Auditing, 
				Opened, 
				[Last Saved], 
				[Open Duration (Sec)], 
				[STC Duration (Sec)], 
				[Session Hours], 
				Groups, 
				[In-place Families], 
				[Unplaced Rooms], 
				[Unenclosed Rooms], 
				Rooms,
				[Unplaced Spaces], 
				[Unenclosed Spaces], 
				Spaces, 
				Views, 
				Phases, 
				[Design Options], 
				Worksets, 
				OpenWorksets,
				Families, 
				[Family Instances], 
				[Unplaced Families], 
				Materials, 
				[View Filters], 
				Warnings, 
				Levels,
				BasePoint,
				SurveyPoint,
				AngleToTrueNorth,
				SiteLatLong
		FROM    ctcvw_Sessions AS Data
		WHERE   ([Last Saved] = (SELECT MAX([Last Saved]) AS Expr1
									FROM ctcvw_Sessions AS ctcvw_Sessions_1
										WHERE ([Central File] = Data.[Central File]) 
										AND (ProjectId = Data.ProjectId))) ')

	PRINT 'PAL - Updating ctcvw_CentralFiles_All'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_CentralFiles_All' )
			DROP VIEW  pal.ctcvw_CentralFiles_All
		EXEC('CREATE VIEW [pal].[ctcvw_CentralFiles_All]
		AS
		SELECT  Id, 
				ProjectId, 
				[Project Number], 
				[Project Name], 
				[Client Name], 
				Contributor, 
				Server, 
				[Central File], 
				[File Name], 
				[Local File], 
				[File Size (MB)], 
				[Revit Version], 
				Auditing, 
				Opened, 
				[Last Saved], 
				[Open Duration (Sec)], 
				[STC Duration (Sec)], 
				[Session Hours], 
				Groups, 
				[In-place Families], 
				[Unplaced Rooms], 
				[Unenclosed Rooms], 
				Rooms,
				[Unplaced Spaces], 
				[Unenclosed Spaces], 
				Spaces, 
				Views, 
				Phases, 
				[Design Options], 
				Worksets, 
				OpenWorksets, 
				Families, 
				[Family Instances], 
				[Unplaced Families], 
				Materials, 
				[View Filters], 
				Warnings, 
				Levels,
				BasePoint,
				SurveyPoint,
				AngleToTrueNorth,
				SiteLatLong
		FROM    ctcvw_Sessions AS Data
		WHERE   (Opened =
					(SELECT MAX(Opened) AS Expr1
						FROM ctcvw_Sessions
						WHERE  ([Central File] = Data.[Central File]) 
						AND (ProjectId = Data.ProjectId) 
						AND (DayOpened = Data.DayOpened))) ')

	PRINT 'PAL - Updating ctcvw_CentralFiles_Current'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_CentralFiles_Current' )
			DROP VIEW  pal.ctcvw_CentralFiles_Current
		EXEC('CREATE VIEW [pal].[ctcvw_CentralFiles_Current]
		AS
		SELECT  Id, 
				ProjectId, 
				[Project Number], 
				[Project Name], 
				[Client Name], 
				Contributor, 
				Server, 
				[Central File], 
				[File Name], 
				[Local File], 
				[File Size (MB)], 
				[Revit Version], 
				Auditing, 
				Opened,
				[Last Saved], 
				[Open Duration (Sec)], 
				[STC Duration (Sec)], 
				[Session Hours], 
				Groups,
				[In-place Families], 
				[Unplaced Rooms], 
				[Unenclosed Rooms], 
				Rooms,
				[Unplaced Spaces], 
				[Unenclosed Spaces], 
				Spaces, 
				Views, 
				Phases, 
				[Design Options], 
				Worksets, 
				OpenWorksets, 
				Families, 
				[Family Instances], 
				[Unplaced Families], 
				Materials, 
				[View Filters], 
				Warnings, 
				Levels,
				BasePoint,
				SurveyPoint,
				AngleToTrueNorth,
				SiteLatLong
		FROM    ctcvw_Sessions AS Data
		WHERE   ([Last Saved] =
				(SELECT MAX([Last Saved]) AS Expr1
					FROM ctcvw_Sessions AS ctcvw_Sessions_1
						WHERE  ([Central File] = Data.[Central File]) 
						AND (ProjectId = Data.ProjectId))) ')

	PRINT 'PAL - Updating ctcvw_FileSizes'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_FileSizes' )
			DROP VIEW  pal.ctcvw_FileSizes
		EXEC('CREATE VIEW [pal].[ctcvw_FileSizes]
		AS
		SELECT  ProjectId, 
				[Central File], 
				[File Name], 
				[File Size (MB)], 
				Opened
		FROM    ctcvw_Sessions AS Data
		WHERE   (Opened = (SELECT   MAX(Opened) AS Expr1
					FROM ctcvw_Sessions
					WHERE   ([Central File] = Data.[Central File]) 
					AND (ProjectId = Data.ProjectId))) ')

	PRINT 'PAL - Updating ctcvw_Links_All'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Links_All' )
		DROP VIEW  pal.ctcvw_Links_All
		EXEC('CREATE VIEW [pal].[ctcvw_Links_All]
		AS
		SELECT  Data.Id AS DocSessionId, 
				Data.[Last Saved] AS [Date Created], 
				LogLink.LinkPath AS [Link Path], 
				LogLink.LinkShortFileName AS [Link Filename], 
				LogLink.LinkType AS [Link Type], 
				LogLink.LinkStatus AS [Link Status]
		FROM    ctcvw_Sessions AS Data 
			INNER JOIN pal.LogLink ON Data.Id = LogLink.DocSessionID
		WHERE (Data.[Last Saved] =
						(SELECT MAX([Last Saved]) AS Expr1
							FROM ctcvw_Sessions AS ctcvw_Sessions_1
							WHERE (Id = Data.Id))) ')

	PRINT 'PAL - Updating ctcvw_Links_Current'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Links_Current' )
			DROP VIEW  pal.ctcvw_Links_Current
		EXEC('CREATE VIEW [pal].[ctcvw_Links_Current]
		AS
		SELECT  LogLink.DocSessionID As DocSessionId, 
				ctcvw_CentralFiles.ProjectId, 
				ctcvw_CentralFiles.[Central File], 
				ctcvw_CentralFiles.[File Name], 
				LogLink.LinkPath AS [Link Path], 
				LogLink.LinkShortFileName AS [Link Filename], 
				LogLink.LinkType AS [Link Type], 
				LogLink.LinkStatus AS [Link Status], 
				LogLink.UserName, 
				LogLink.LinksDateTime
		FROM    ctcvw_CentralFiles 
			INNER JOIN pal.LogLink ON ctcvw_CentralFiles.Id = LogLink.DocSessionID ')

	PRINT 'PAL - Updating ctcvw_Machines'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Machines' )
		DROP VIEW  pal.ctcvw_Machines
		EXEC('CREATE VIEW [pal].[ctcvw_Machines]
		AS
		SELECT DocSessionID, 
			MAX(ID) AS ID, 
			MAX(ProcessorId) AS ProcessorId, 
			MAX(MachineName) AS MachineName, 
			MAX(MAC) AS MAC, 
			MAX(OperatingSystem) AS OperatingSystem, 
			MAX(HDD) AS HDD, 
			MAX(Motherboard) AS Motherboard, 
			MAX(Bios) AS Bios, 
			MAX(RAM) AS RAM, 
			MAX(RAM_Slots) AS RAM_Slots, 
			MAX(CPU) AS CPU, 
			MAX(Video) AS Video, 
			MAX(LogDateTime) AS LogDateTime, 
			MAX(IPAddress) AS IPAddress
		FROM pal.LogMachine
		GROUP BY DocSessionID' )
			
	PRINT 'PAL - Updating ctcvw_Machines_All'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Machines_All' )
		DROP VIEW  pal.ctcvw_Machines_All
		EXEC('CREATE VIEW [pal].[ctcvw_Machines_All]
		AS
		SELECT  LogMachine.DocSessionID As DocSessionId, 
				LogMachine.MachineName, 
				LogMachine.IPAddress, 
				LogMachine.OperatingSystem, 
				LogMachine.CPU, 
				LogMachine.RAM, 
				LogMachine.RAM_Slots, 
				LogMachine.Video, 
				LogMachine.HDD, 
				LogMachine.MAC, 
				LogMachine.LogDateTime AS [Date Created]
		FROM    ctcvw_Sessions 
			INNER JOIN pal.LogMachine 
			ON ctcvw_Sessions.Id = LogMachine.DocSessionID ')

	PRINT 'PAL - Updating ctcvw_Machines_Current'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Machines_Current' )
		DROP VIEW  pal.ctcvw_Machines_Current
		EXEC('CREATE VIEW [pal].[ctcvw_Machines_Current]
		AS
		SELECT  DocSessionID As DocSessionId, 
				MachineName, 
				IPAddress, 
				OperatingSystem, 
				CPU, 
				RAM, 
				RAM_Slots, 
				Video, 
				HDD, 
				MAC, 
				LogDateTime AS [Date Created]
		FROM    pal.LogMachine AS Data
		WHERE   (LogDateTime =
						(SELECT MAX(LogDateTime) AS Expr1
						FROM pal.LogMachine
						WHERE (MachineName = Data.MachineName))) ')

	PRINT 'PAL - Updating ctcvw_Views_All'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Views_All' )
			DROP VIEW  pal.ctcvw_Views_All
		EXEC('CREATE VIEW [pal].[ctcvw_Views_All]
		AS
		SELECT  Data.Id AS DocSessionId, 
				Data.[Last Saved] AS [Date Created], 
				LogViewType.ViewTypeName AS [View Types], 
				LogViewType.ViewCt AS Views
		FROM    ctcvw_Sessions AS Data 
			INNER JOIN  pal.LogViewType 
			ON Data.Id = LogViewType.DocSessionID
		WHERE (Data.[Last Saved] =
				(SELECT MAX([Last Saved]) AS Expr1
					FROM ctcvw_Sessions AS ctcvw_Sessions_1
					WHERE (Id = Data.Id))) ')

	PRINT 'PAL - Updating ctcvw_Views_Current'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Views_Current' )
			DROP VIEW  pal.ctcvw_Views_Current
		EXEC('CREATE VIEW [pal].[ctcvw_Views_Current]
		AS
		SELECT  LogViewType.DocSessionID As DocSessionId, 
				ctcvw_CentralFiles.ProjectId, 
				ctcvw_CentralFiles.[Central File], 
				ctcvw_CentralFiles.[File Name], 
				LogViewType.ViewTypeName AS [View Types], 
				LogViewType.ViewCt AS Views, 
				LogViewType.ViewDateTime AS [Date Created]
		FROM    ctcvw_CentralFiles 
			INNER JOIN pal.LogViewType 
			ON ctcvw_CentralFiles.Id = LogViewType.DocSessionID ')

	PRINT 'PAL - Updating ctcvw_Warnings'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Warnings' )
			DROP VIEW  pal.ctcvw_Warnings
		EXEC('CREATE VIEW [pal].[ctcvw_Warnings]
		AS
		SELECT        
			DocSessionID, 
			MAX(Severity) AS Severity, 
			MAX(Description) AS Description, 
			MAX(ElementId) AS ElementId, 
			MAX(ElementName) AS ElementName, 
			MAX(LevelName) AS LevelName, 
			MAX(Workset) AS Workset, 
			MAX(WarningDateTime) AS WarningDateTime, 
			MAX(ID) AS ID, 
			MAX(CAST(WarningId AS varchar(36))) AS WarningId,
			MAX(''--'') AS x 
		FROM  pal.LogWarning
		GROUP BY DocSessionID ')
			
	PRINT 'PAL - Updating ctcvw_Warnings_All'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Warnings_All' )
			DROP VIEW  pal.ctcvw_Warnings_All
		EXEC('CREATE VIEW [pal].[ctcvw_Warnings_All]
		AS
		SELECT  LogWarning.DocSessionID As DocSessionId, 
				LogWarning.Severity, 
				LogWarning.Description, 
				LogWarning.ElementId, 
				LogWarning.ElementName, 
				LogWarning.LevelName AS [Level Name], 
				LogWarning.Workset, 
				LogWarning.WarningDateTime AS [Date Created]
		FROM    ctcvw_Sessions 
			INNER JOIN  pal.LogWarning 
			ON ctcvw_Sessions.Id = LogWarning.DocSessionID ')

	PRINT 'PAL - Updating ctcvw_Warnings_Current'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcvw_Warnings_Current' )
			DROP VIEW  pal.ctcvw_Warnings_Current
		EXEC('CREATE VIEW [pal].[ctcvw_Warnings_Current]
		AS
		SELECT  LogWarning.DocSessionID As DocSessionId, 
				ctcvw_CentralFiles_Current.ProjectId, 
				ctcvw_CentralFiles_Current.[Central File], 
				ctcvw_CentralFiles_Current.[File Name], 
				LogWarning.WarningDateTime AS [Date Created], 
				LogWarning.WarningId, 
				LogWarning.Severity, 
				LogWarning.Description, 
				LogWarning.ElementId, 
				LogWarning.ElementName, 
				LogWarning.LevelName AS [Level Name], 
				LogWarning.Workset
		FROM    ctcvw_CentralFiles_Current 
			INNER JOIN pal.LogWarning 
			ON ctcvw_CentralFiles_Current.Id = LogWarning.DocSessionID ')
			
	--------------------------------------------------------------------------------
	PRINT 'End upgrading PAL Views to new int IDs'
	--------------------------------------------------------------------------------
	PRINT ''
	--------------------------------------------------------------------------------
	PRINT 'Upgrading PAL Stored Procs to new int IDs'
	--------------------------------------------------------------------------------
	PRINT ' '
	PRINT 'PAL - Updating ctcsp_Upd_LogSession'	
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogSession' )
		DROP PROCEDURE [pal].ctcsp_Upd_LogSession
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogSession]
	(
		@ID uniqueidentifier,
		@EndDateTime datetime
	)

	AS
	BEGIN
		SET NOCOUNT OFF;

	UPDATE [pal].[LogSession] 
	SET EndDateTime = @EndDateTime
	WHERE (([ID] = @ID));

	END	 ');
	
	PRINT ' '
	
	PRINT 'PAL - Updating ctcsp_Upd_LogSession2'	
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogSession2' )
		DROP PROCEDURE [pal].ctcsp_Upd_LogSession2
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogSession2]
	(
	    @ResultCount int output,
		@ID uniqueidentifier,
		@EndDateTime datetime
	)

	AS
	BEGIN
		SET NOCOUNT OFF;

	UPDATE [pal].[LogSession] 
	SET EndDateTime = @EndDateTime
	WHERE (([ID] = @ID));

	SET @ResultCount=@@ROWCOUNT
	RETURN @ResultCount

	END	
	
	' )
	
	PRINT ' '
	
	PRINT 'PAL - Updating ctcsp_Get_CurrentActivitySchemaVersion'		

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_CurrentActivitySchemaVersion' )
		DROP PROCEDURE [pal].ctcsp_Get_CurrentActivitySchemaVersion
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_CurrentActivitySchemaVersion]
	(
		@SchemaVersion int OUTPUT 
	)
	AS
	BEGIN
		SET NOCOUNT ON;

		SELECT TOP 1 @SchemaVersion = CurrentActivitySchemaVersion
		FROM asset.SchemaData

	RETURN @SchemaVersion
	END ');

		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_DistinctProjectPaths' )
			DROP PROCEDURE [pal].ctcsp_Get_DistinctProjectPaths
		EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_DistinctProjectPaths] 
		(
			@p_CompanyID int
		)	
		AS
		BEGIN

			SELECT DISTINCT
				ISNULL(pp.ID, 0) AS ID
				,LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) As CentralFileNameOrFolder
				,ISNULL(pr.ProjectNumber, ''unassigned'') AS ProjectNumber
				,pr.ID AS ProjectID
			FROM pal.LogDocSession AS s 
				LEFT OUTER JOIN asset.Project AS pr 
				INNER JOIN asset.ProjectPath AS pp ON pr.ID = pp.ProjectID
				ON LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath 
					
			WHERE (s.CompanyID = @p_CompanyID) 
			
			ORDER BY ProjectNumber, CentralFileNameOrFolder

			END 
	');
			
	PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithConflictingProjectIds'	
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithConflictingProjectIds' )
		DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithConflictingProjectIds
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithConflictingProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		SELECT  s.ID, 
				s.CentralFileName, 
				s.ShortFileName, 
				s.ProjectID AS DocProjectID, 
				asset.Project.ProjectNumber AS DocProjectNumber, 
				pp.ProjectID AS ProjProjectID, 
				pr.ProjectNumber AS ProjProjectNumber, 
				s.DocDateTime, 
				pp.AddedDate AS ProjDateTime 
		FROM    pal.LogDocSession AS s
			INNER JOIN asset.ProjectPath AS pp
				ON	LEFT(s.CentralFileName, LEN(s.CentralFileName) - CHARINDEX(''\'', REVERSE(s.CentralFileName), 1)) = pp.CentralFilePath 
					AND s.ProjectID <> pp.ProjectID 
					INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
					INNER JOIN asset.Project ON s.ProjectID = asset.Project.ID
		WHERE   (s.CompanyID = @p_CompanyID)
		AND     (pr.CompanyID = @p_CompanyID)
		ORDER BY s.CentralFileName, s.ProjectID, s.DocDateTime, pp.AddedDate
			
	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithDeletedProjectIds'	
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithDeletedProjectIds' )
		DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithDeletedProjectIds
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithDeletedProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN
	SET NOCOUNT ON;
			
		SELECT 
			s.ID,
			s.CentralFileName, 
			s.ShortFileName,
			s.ProjectID AS DocProjectID,
			''deleted'' AS DocProjectNumber,
			pp.ProjectID AS ProjProjectID, 
			pr.ProjectNumber AS ProjProjectNumber,
			s.DocDateTime,
			pp.AddedDate AS ProjDateTime
		FROM pal.LogDocSession AS s
		LEFT JOIN asset.Project As p ON p.ID = s.ProjectID 
		INNER JOIN asset.ProjectPath As pp 
			ON LEFT(s.CentralFileName, LEN(s.CentralFileName) - CHARINDEX(''\'', REVERSE(s.CentralFileName), 1)) = pp.CentralFilePath
		INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
		WHERE   (s.CompanyID = @p_CompanyID) 
		AND     (pr.CompanyID = @p_CompanyID)
		AND		(p.ID IS NULL)
		ORDER BY CentralFileName, DocProjectID, DocDateTime, ProjDateTime
	END ');
				
				
				
	PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithEmptyProjectIds'	
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithEmptyProjectIds' )
		DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithEmptyProjectIds
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithEmptyProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		SELECT  
			s.ID,       
			s.CentralFileName, 
			s.ShortFileName, 
			0 AS DocProjectID, 
			pr.ProjectNumber AS DocProjectNumber, 
			pp.ProjectID AS ProjProjectID, 
			pr.ProjectNumber AS ProjProjectNumber, 
			s.DocDateTime,
			pp.AddedDate AS ProjDateTime 
		FROM pal.LogDocSession AS s
			INNER JOIN
				asset.ProjectPath As pp ON 
				LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath
				AND s.ProjectID is null
				INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
		WHERE (s.CompanyID = @p_CompanyID) 
		AND   (s.ProjectID IS NULL)
		ORDER BY CentralFileName, DocProjectID, DocDateTime, ProjDateTime
	END 
	
	');

			
			
	PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithNoProject'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithNoProject' )
		DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithNoProject
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithNoProject] 
	(
		@p_CompanyID int
	)	
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

	SELECT distinct
		LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) As CentralFileName
	FROM pal.LogDocSession AS s 
		LEFT OUTER JOIN asset.Project AS pr 
		INNER JOIN asset.ProjectPath AS pp ON pr.ID = pp.ProjectID 
		ON LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath 
		--AND s.ProjectID <> pp.ProjectID
	WHERE (s.CompanyID = @p_CompanyID) 
	
	AND (s.ProjectID IS NULL) 
	AND (pp.ProjectID IS NULL)
	ORDER BY CentralFileName

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds' )
		DROP PROCEDURE [pal].ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds] 
	(
		@p_CompanyID int
	)	
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		SELECT        
			s.ID,
			s.CentralFileName,
			s.ShortFileName, 
			s.ProjectID AS DocProjectID, 
			asset.Project.ProjectNumber AS DocProjectNumber, 
			pp.ProjectID AS ProjProjectID, 
			pr.ProjectNumber AS ProjProjectNumber, 
			s.DocDateTime,
			pp.AddedDate AS ProjDateTime
		FROM pal.LogDocSession As s
			INNER JOIN
				asset.ProjectPath As pp
				ON LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath 
				AND s.ProjectID <> pp.ProjectID 
			INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
			INNER JOIN asset.Project ON s.ProjectID = asset.Project.ID
		WHERE (s.CompanyID = @p_CompanyID) 
		AND   (pr.CompanyID = @p_CompanyID)
		AND (s.ProjectID IS NOT NULL)
		ORDER BY CentralFileName, DocProjectID, DocDateTime, ProjDateTime

	END' );

			
			
	PRINT 'PAL - Updating ctcsp_Get_MappedProjectPathsFromLogDocSessions'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_MappedProjectPathsFromLogDocSessions' )
		DROP PROCEDURE [pal].ctcsp_Get_MappedProjectPathsFromLogDocSessions
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_MappedProjectPathsFromLogDocSessions] 
	(
		@p_CompanyID int
	)	
	AS
	BEGIN

		SELECT DISTINCT
			pp.ID
			,LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) As CentralFileName
			,pr.ProjectNumber AS DocProjectNumber
			,pr.ID AS DocProjectID
		FROM pal.LogDocSession AS s 
			LEFT OUTER JOIN asset.Project AS pr 
			INNER JOIN asset.ProjectPath AS pp ON pr.ID = pp.ProjectID
			ON LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath 
				
		WHERE (s.CompanyID = @p_CompanyID) 
		AND   (pr.CompanyID = @p_CompanyID) 
		AND   (pp.ProjectID IS NOT NULL)
		ORDER BY DocProjectNumber, CentralFileName

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Get_ProjectPaths'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_ProjectPaths' )
		DROP PROCEDURE [pal].[ctcsp_Get_ProjectPaths]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_ProjectPaths] 
	(
		@p_CompanyID int
	)	
	AS
	BEGIN

		SELECT pp.ID, 
			pp.ProjectID, 
			pp.AddedByUserID, 
			pp.AddedDate, 
			pp.CentralFilePath, 
			pr.CompanyID
		FROM   asset.ProjectPath AS pp
		INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID
		WHERE (CompanyID = @p_CompanyID) 
		ORDER BY [AddedDate]

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Get_ProjectPathsFromLogDocSessions'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_ProjectPathsFromLogDocSessions' )
		DROP PROCEDURE [pal].[ctcsp_Get_ProjectPathsFromLogDocSessions]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_ProjectPathsFromLogDocSessions]
	(
		@p_CompanyID int
	)	 
	AS
	BEGIN
			
		SET NOCOUNT ON;

		SELECT DISTINCT
			ISNULL(pp.ID, 0) AS ID
			,LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) As CentralFileName
			,ISNULL(pr.ProjectNumber, ''0'') AS DocProjectNumber
			,ISNULL(pr.ID, 0)  AS DocProjectID
		FROM pal.LogDocSession As s
			LEFT OUTER JOIN asset.Project AS pr 
			INNER JOIN asset.ProjectPath As pp ON pr.ID = pp.ProjectID
			ON LEFT(s.CentralFileName,LEN(s.CentralFileName) - charindex(''\'',reverse(s.CentralFileName),1)) = pp.CentralFilePath 
			AND s.ProjectID <> pp.ProjectID
		WHERE (s.CompanyID = @p_CompanyID) 
		ORDER BY CentralFileName

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Get_Projects'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Projects' )
		DROP PROCEDURE [pal].[ctcsp_Get_Projects]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Projects] 
	
	AS
	BEGIN
			
		SET NOCOUNT ON;

		SELECT 
				[Id]
				,[Project]
				,[Project Number]
				,[Project Name]
				,[Client Name]
				,[Issue Date]
				,[Days Until Issue]
				,[Office]
				,[BuildingName]
				,[ClientName]
				,[StreetAddress]
				,[StreetAddress2]
				,[StreetAddress3]
				,[ProjectPhase]
				,[Author]
				,[City]
				,[StateOrProvince]
				,[PostalCode]
				,[CountryName]
				,[OrgName]
				,[OrgDescription]
				,AddedDate
		FROM pal.ctcvw_Projects 
		ORDER BY [Project Number]

	END ');

	PRINT 'PAL - Updating ctcsp_Get_Projects'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Projects_Full' )
		DROP PROCEDURE [pal].[ctcsp_Get_Projects_Full]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Projects_Full] 
	(
		@p_CompanyID int
	)		
	AS
	BEGIN

		SET NOCOUNT ON;

		SELECT 
				[ID]
				,[Office]
				,[ProjectNumber]
				,[ProjectName]
				,[BuildingName]
				,[ClientName]
				,[StreetAddress]
				,[StreetAddress2]
				,[StreetAddress3]
				,[ProjectPhase]
				,[ProjectIssueDate]
				,[Author]
				,[City]
				,[StateOrProvince]
				,[PostalCode]
				,[CountryName]
				,[OrgName]
				,[OrgDescription]
				,[AddedDate]
				,[UpdatedDate]
		FROM asset.Project
		WHERE (CompanyID = @p_CompanyID) 
		ORDER BY [ProjectNumber]

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_LogDocSessions_DeleteByDateAndCentralFileName'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_LogDocSessions_DeleteByDateAndCentralFileName' )
		DROP PROCEDURE [pal].[ctcsp_LogDocSessions_DeleteByDateAndCentralFileName]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_LogDocSessions_DeleteByDateAndCentralFileName]
	(
		@p_CompanyID int,
		@ItemName nvarchar(255),
		@DateFrom DateTime,
		@DateTo DateTime
	)
	AS
		SET NOCOUNT OFF;
			
	BEGIN
		IF (@ItemName = ''all'')
			BEGIN
				DELETE [pal].[LogDocSession] 
				FROM LogDocSession 
				WHERE (CompanyID = @p_CompanyID) 
				AND LogDocSession.DocDateTime BETWEEN @DateFrom AND @DateTo
			END
		ELSE
			BEGIN
					DELETE [pal].[LogDocSession] 
					FROM LogDocSession
					WHERE (CompanyID = @p_CompanyID) 
					AND LogDocSession.DocDateTime BETWEEN @DateFrom AND @DateTo
					AND CentralFileName = @ItemName
			END

		RETURN @@RowCount

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_LogDocSessions_UpdateHasClosed_ByUserAndMachineName'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_LogDocSessions_UpdateHasClosed_ByUserAndMachineName' )
		DROP PROCEDURE [pal].[ctcsp_LogDocSessions_UpdateHasClosed_ByUserAndMachineName]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_LogDocSessions_UpdateHasClosed_ByUserAndMachineName]
	(
		@p_CompanyID int,
		@UserName NVARCHAR(100),
		@MachineName NVARCHAR(255)
			
	)
	AS
		SET NOCOUNT OFF;
			
	BEGIN

		UPDATE pal.LogDocSession       
			SET HasClosed = 1
		FROM LogDocSession 
		INNER JOIN LogMachine As m ON LogDocSession.ID = m.DocSessionID
		WHERE (LogDocSession.CompanyID = @p_CompanyID) 
			AND (HasClosed = 0)
			AND  (UserName = @UserName)
			AND  (m.MachineName = @MachineName)
			AND (DocDateTime BETWEEN CAST(GETDATE() AS DATE) AND DATEADD(DAY, 1, CAST(GETDATE() AS DATE)))

		RETURN @@RowCount
	SET NOCOUNT ON;
	END ');

			
			
	PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDate'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDate' )
		DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDate]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDate]
	(
		@p_CompanyID int,
		@DateFrom DateTime,
		@DateTo DateTime,
		@IsSnapshot bit
	)
	AS
		SET NOCOUNT OFF;
			
	BEGIN
		IF (@IsSnapshot = 0)
			DELETE d
			FROM pal.LogDocSession As d 
			WHERE (d.CompanyID = @p_CompanyID) 
			AND (d.DocDateTime BETWEEN @DateFrom AND @DateTo)
		ELSE
			DELETE p
			FROM snapshot.ProjectFileSnapshot As p
			WHERE (p.CompanyID = @p_CompanyID) 
			AND   (p.SnapshotDateAndTime BETWEEN @DateFrom AND @DateTo)

	RETURN @@RowCount

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDateAndProjectID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDateAndProjectID' )
		DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDateAndProjectID]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_DeleteByDateAndProjectID]
	(
		@p_CompanyID int,
		@ProjectID int,
		@DateFrom DateTime,
		@DateTo DateTime,
		@IsSnapshot bit
	)
	AS
		SET NOCOUNT OFF;
			
	BEGIN

		IF (@IsSnapshot = 0)
			DELETE s
			FROM pal.LogDocSession As s
			WHERE (s.CompanyID = @p_CompanyID)
			AND   (s.DocDateTime BETWEEN @DateFrom AND @DateTo)
			AND   (s.ProjectID = @ProjectID)
		ELSE
			DELETE ps
			FROM snapshot.ProjectFileSnapshot As ps
				INNER JOIN snapshot.ProjectFile ON ps.ProjectFileID = ProjectFile.ID 
			WHERE (ps.CompanyID = @p_CompanyID)
			AND   (ps.SnapshotDateAndTime BETWEEN @DateFrom AND @DateTo)
			AND   (ProjectFile.ProjectID = @ProjectID)

	RETURN @@RowCount

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadAll'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadAll' )
		DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadAll]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadAll]
	(
		@p_CompanyID int,
		@IsSnapshot bit
	)
	AS

	BEGIN

		SET NOCOUNT ON;
			
		IF (@IsSnapshot = 0)
			SELECT 
				NEWID() AS ItemID
				,Data.ProjectID AS ProjectID 
				,Data.CentralFileName AS ItemName
				,MIN(pr.ProjectNumber) AS ProjectNumber 
				,MIN(Data.DocDateTime) AS ItemDateTime
			FROM pal.LogDocSession AS Data 
			INNER JOIN asset.Project As pr ON Data.ProjectID = pr.ID
			WHERE (Data.CompanyID = @p_CompanyID)
			GROUP BY Data.ProjectID, Data.CentralFileName
			ORDER BY MIN(pr.ProjectNumber), ItemName, MIN(Data.DocDateTime)
		ELSE
			SELECT  
				pfs.ID AS ItemID
				,pf.ProjectID
				,p.ProjectNumber 
				,pfs.SnapshotName AS ItemName
				,pfs.SnapshotDateAndTime AS ItemDateTime
				
			FROM snapshot.ProjectFileSnapshot As pfs
				INNER JOIN snapshot.ProjectFile As pf ON pfs.ProjectFileID = pf.ID 
				INNER JOIN asset.Project As p ON pf.ProjectID = p.ID
			WHERE (pfs.CompanyID = @p_CompanyID)
			ORDER BY pfs.SnapshotDateAndTime
	END ');

			
			
	PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDate'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDate' )
		DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDate]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDate]
	(
		@p_CompanyID int,
		@DateFrom DateTime,
		@DateTo DateTime,
		@IsSnapshot bit
	)
	AS

	BEGIN
	SET NOCOUNT ON;
		IF (@IsSnapshot = 0)
				
			SELECT 
				NEWID() AS ItemID
				,Data.ProjectID AS ProjectID 
				,Data.CentralFileName AS ItemName
				,MIN(pr.ProjectNumber) AS ProjectNumber 
				,MIN(Data.DocDateTime) AS ItemDateTime
			FROM pal.LogDocSession AS Data 
				
			INNER JOIN asset.Project As pr ON Data.ProjectID = pr.ID
			WHERE (Data.CompanyID = @p_CompanyID)
			AND Data.DocDateTime BETWEEN @DateFrom AND @DateTo
			GROUP BY Data.ProjectID, Data.CentralFileName
			ORDER BY MIN(pr.ProjectNumber), ItemName, MIN(Data.DocDateTime)
		ELSE
			SELECT  
				pfs.ID AS ItemID
				,pf.ProjectID
				,pr.ProjectNumber 
				,pfs.SnapshotName AS ItemName
				,pfs.SnapshotDateAndTime AS ItemDateTime

			FROM snapshot.ProjectFileSnapshot As pfs
				INNER JOIN snapshot.ProjectFile As pf ON pfs.ProjectFileID = pf.ID 
				INNER JOIN asset.Project As pr ON pf.ProjectID = pr.ID
			WHERE (pfs.CompanyID = @p_CompanyID)
			AND   (pfs.SnapshotDateAndTime BETWEEN @DateFrom AND @DateTo)
			ORDER BY pfs.SnapshotDateAndTime
	END ');

			
			
	PRINT 'PAL - Updating ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDateAndProjectID'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDateAndProjectID' )
		DROP PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDateAndProjectID]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_ProjectFileSnapshotOrLogDocSessions_ReadByDateAndProjectID]
	(
		@ProjectID int,
		@DateFrom DateTime,
		@DateTo DateTime,
		@IsSnapshot bit
	)
	AS
	BEGIN

		SET NOCOUNT ON;
			
		IF (@IsSnapshot = 0)
			SELECT 
				NEWID() AS ItemID
				,Data.ProjectID AS ProjectID 
				,Data.CentralFileName AS ItemName
				,MIN(pr.ProjectNumber) AS ProjectNumber 
				,MIN(Data.DocDateTime) AS ItemDateTime
			FROM pal.LogDocSession AS Data 
			INNER JOIN asset.Project As pr ON Data.ProjectID = pr.ID
			WHERE Data.DocDateTime BETWEEN @DateFrom AND @DateTo
			AND ProjectID = @ProjectID
			GROUP BY Data.ProjectID, Data.CentralFileName
			ORDER BY MIN(pr.ProjectNumber), ItemName, MIN(Data.DocDateTime)
		ELSE
			SELECT  
				pfs.ID AS ItemID
				,pf.ProjectID
				,pr.ProjectNumber 
				,pfs.SnapshotName AS ItemName
				,pfs.SnapshotDateAndTime AS ItemDateTime

			FROM snapshot.ProjectFileSnapshot As pfs
				INNER JOIN snapshot.ProjectFile As pf ON pfs.ProjectFileID = pf.ID 
				INNER JOIN asset.Project As pr ON pf.ProjectID = pr.ID
			WHERE pfs.SnapshotDateAndTime BETWEEN @DateFrom AND @DateTo
			AND ProjectID = @ProjectID
			ORDER BY pfs.SnapshotDateAndTime
					
		END ');

				
				
	--PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_Changes'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_Changes' )
		DROP PROCEDURE [pal].ctcsp_Upd_LogDocSessions_Changes
			
			
	--PRINT 'PAL - Drop ctcsp_Upd_LogDocSessions_HasClosed'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_HasClosed' )
		DROP PROCEDURE [pal].ctcsp_Upd_LogDocSessions_HasClosed
			
			
	PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds' )
		DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds] 
	(
		@p_CompanyID int,
		@p_UserName NVARCHAR(100)
	)
	AS
	BEGIN

		SET NOCOUNT ON;

		INSERT INTO pal.LogDocumentProjChange(
			 [DocSessionID]
			,[CentralFileName]
			,[UserName]
			,[OldProjID]
			,[NewProjID]
			,[DateCreated])
		SELECT ds.ID, ds.CentralFileName, @p_UserName, ds.ProjectID, pp.ProjectID, GETUTCDATE()
		FROM pal.LogDocSession as ds
		INNER JOIN
			asset.ProjectPath as pp
			ON LEFT(ds.CentralFileName,LEN(ds.CentralFileName) - charindex(''\'',reverse(ds.CentralFileName),1)) = pp.CentralFilePath 
			AND ds.ProjectID <> pp.ProjectID 
			INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
			INNER JOIN asset.Project ON ds.ProjectID = asset.Project.ID
		WHERE (ds.CompanyID = @p_CompanyID)
		AND   (pr.CompanyID = @p_CompanyID)
		AND   (ds.ProjectID IS NOT NULL)

		SET NOCOUNT OFF;

		UPDATE ds
		SET ds.ProjectID = pp.ProjectID
		FROM pal.LogDocSession as ds
		INNER JOIN
			asset.ProjectPath as pp
			ON LEFT(ds.CentralFileName,LEN(ds.CentralFileName) - charindex(''\'',reverse(ds.CentralFileName),1)) = pp.CentralFilePath 
			AND ds.ProjectID <> pp.ProjectID 
			INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
			INNER JOIN asset.Project ON ds.ProjectID = asset.Project.ID
		WHERE (ds.CompanyID = @p_CompanyID)
		AND   (pr.CompanyID = @p_CompanyID)
		AND   (ds.ProjectID IS NOT NULL)

		Return @@ROWCOUNT;

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds' )
		DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN

		SET NOCOUNT OFF;
		UPDATE t1
		SET t1.ProjectID = t2.ProjectID
		FROM pal.LogDocSession AS t1
		LEFT JOIN asset.Project As pr ON pr.ID = t1.ProjectID 
		INNER JOIN asset.ProjectPath AS t2
		ON LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = t2.CentralFilePath
		INNER JOIN asset.Project AS t3 ON t2.ProjectID = t3.ID
		WHERE (t1.CompanyID = @p_CompanyID)
		AND   (pr.CompanyID = @p_CompanyID)
		AND (pr.ID IS NULL)
	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds' )
		DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds] 
	(
		@p_CompanyID int,
		@p_UserName NVARCHAR(100)
	)
	AS
	BEGIN

		SET NOCOUNT ON;

		INSERT INTO pal.LogDocumentProjChange(
			[DocSessionID]
			,[CentralFileName]
			,[UserName]
			,[OldProjID]
			,[NewProjID]
			,[DateCreated])
		SELECT t1.ID, t1.CentralFileName, @p_UserName, t1.ProjectID, t2.ProjectID, GETUTCDATE()
		FROM pal.LogDocSession AS t1
				INNER JOIN asset.ProjectPath AS t2
				ON LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = t2.CentralFilePath
				WHERE (t1.CompanyID = @p_CompanyID)
				AND (t1.ProjectID IS NULL)

		SET NOCOUNT OFF;

		UPDATE t1
				SET t1.ProjectID = t2.ProjectID
				FROM pal.LogDocSession AS t1
				INNER JOIN asset.ProjectPath AS t2
				ON LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = t2.CentralFilePath
				WHERE (t1.CompanyID = @p_CompanyID)
				AND (t1.ProjectID IS NULL)

		Return @@ROWCOUNT;
	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceProjectId'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceProjectId' )
		DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectId]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectId] 
	(
		@p_ID int
		,@p_ProjectID int
	)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.

		-- Specify in which table the row exists to update
		UPDATE pal.LogDocSession
			
		-- Specify which parameter value goes into which fields
		SET ProjectID = @p_ProjectID
			
		-- Specify how to find which record to update
		WHERE ID = @p_ID

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath' )
		DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath] 
	(
		@p_CompanyID int,
		@ProjectID int,
		@UserName NVARCHAR(100), 
		@Path NVARCHAR(255)
	) 
	AS
	BEGIN

		SET NOCOUNT ON;

		INSERT INTO pal.LogDocumentProjChange(
			[DocSessionID]
			,[CentralFileName]
			,[UserName]
			,[OldProjID]
			,[NewProjID]
			,[DateCreated])
		SELECT t1.ID, t1.CentralFileName, @UserName, t1.ProjectID, @ProjectID, GETUTCDATE()
		FROM pal.LogDocSession AS t1
		WHERE (t1.CompanyID = @p_CompanyID)
		AND LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = @Path;

		SET NOCOUNT OFF;

		UPDATE pal.LogDocSession
		SET ProjectID = @ProjectID
		WHERE (pal.LogDocSession.CompanyID = @p_CompanyID)
		AND LEFT(pal.LogDocSession.CentralFileName,LEN(pal.LogDocSession.CentralFileName) - charindex(''\'',reverse(pal.LogDocSession.CentralFileName),1)) = @Path;

		Return @@ROWCOUNT;
	END ');

	--PRINT 'PAL - Drop ctcsp_Upd_LogDocSessions_STC'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_STC' )
		DROP PROCEDURE [pal].ctcsp_Upd_LogDocSessions_STC
			
			
	--PRINT 'PAL - Drop ctcsp_Upd_LogDocSessions_Summary'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_Summary' )
		DROP PROCEDURE [pal].ctcsp_Upd_LogDocSessions_Summary
			
			
	--PRINT 'PAL - Drop ctcsp_Upd_LogDocSessions_Warnings'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_Warnings' )
		DROP PROCEDURE [pal].ctcsp_Upd_LogDocSessions_Warnings

			
			
	PRINT 'PAL - Updating ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath' )
		DROP PROCEDURE [pal].[ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath] 
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath] 
	(
		@p_CompanyID int,
		@ProjectID int,
		@UserName NVARCHAR(100), 
		@Path NVARCHAR(255)
	)
	AS
	BEGIN

		SET NOCOUNT ON;

		INSERT INTO pal.LogDocumentProjChange(
			[DocSessionID]
			,[CentralFileName]
			,[UserName]
			,[OldProjID]
			,[NewProjID]
			,[DateCreated])
		SELECT t1.ID, t1.CentralFileName, @UserName, t1.ProjectID, @ProjectID, GETUTCDATE()
		FROM pal.LogDocSession AS t1
		WHERE (t1.CompanyID = @p_CompanyID)
		AND LEFT(t1.CentralFileName, LEN(t1.CentralFileName) - CHARINDEX(''\'', REVERSE(t1.CentralFileName), 1)) = @Path;

		SET NOCOUNT OFF;

		UPDATE pal.LogDocSession
		SET ProjectID = @ProjectID
		WHERE (CompanyID = @p_CompanyID)
		AND LEFT(CentralFileName,LEN(CentralFileName) - charindex(''\'',reverse(CentralFileName),1)) = @Path;

		-- TODO: Add CompanyID
		UPDATE snapshot.ProjectFile
		SET ProjectID = @ProjectID
		WHERE (CompanyID = @p_CompanyID)
		AND LEFT(snapshot.ProjectFile.CentralOrSingleUserProjectFileName,LEN(snapshot.ProjectFile.CentralOrSingleUserProjectFileName) - charindex(''\'',reverse(snapshot.ProjectFile.CentralOrSingleUserProjectFileName),1)) = @Path COLLATE SQL_Latin1_General_CP1_CI_AS;

		SET NOCOUNT ON;

		Return @@ROWCOUNT;
	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Upd_Projects_NonNull'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_Project_NonNull' )
		DROP PROCEDURE [pal].[ctcsp_Upd_Project_NonNull] 
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_Project_NonNull]
	(
		@ID int,
		@Office nvarchar(50),
		@ProjectNumber nvarchar(50),
		@ProjectName nvarchar(255),
		@BuildingName nvarchar(100),
		@ClientName nvarchar(50),
		@StreetAddress nvarchar(100) = NULL ,
		@StreetAddress2 nvarchar(100),
		@StreetAddress3 nvarchar(100),
		@ProjectStatus nvarchar(25),
		@ProjectIssueDate nvarchar(24),
		@Author nvarchar(50),
		@City nvarchar(100),
		@StateOrProvince nvarchar(25),
		@PostalCode nvarchar(12),
		@CountryName nvarchar(35),
		@OrgName nvarchar(100),
		@OrgDescription nvarchar(2048),
		@LastUpdated datetime
	)

	AS
	BEGIN
		SET NOCOUNT OFF;

	UPDATE [asset].[Project] SET 
		[Office] = @Office,
		[ProjectNumber] = @ProjectNumber,
		[ProjectName] = CASE WHEN (@ProjectName = '''') THEN ProjectName ELSE @ProjectName END,
		[BuildingName] = (CASE WHEN (@BuildingName = '''') THEN BuildingName ELSE @BuildingName END),
		[ClientName] = (CASE WHEN (@ClientName = '''') THEN ClientName ELSE @ClientName END),
		[StreetAddress] = (CASE WHEN (@StreetAddress = '''') THEN StreetAddress ELSE @StreetAddress END),
		[StreetAddress2] = (CASE WHEN (@StreetAddress2 = '''') THEN StreetAddress2 ELSE @StreetAddress2 END),
		[StreetAddress3] = (CASE WHEN (@StreetAddress3 = '''') THEN StreetAddress3 ELSE @StreetAddress3 END),
		[ProjectPhase] = (CASE WHEN (@ProjectStatus = '''') THEN ProjectPhase ELSE @ProjectStatus END),
		[ProjectIssueDate] = (CASE WHEN (@ProjectIssueDate = '''') THEN ProjectIssueDate ELSE @ProjectIssueDate END),
		[Author] = (CASE WHEN (@Author = '''') THEN Author ELSE @Author END),
		[City] = (CASE WHEN (@City = '''') THEN City ELSE @City END),
		[StateOrProvince] = (CASE WHEN (@StateOrProvince = '''') THEN StateOrProvince ELSE @StateOrProvince END),
		[PostalCode] = (CASE WHEN (@PostalCode = '''') THEN PostalCode ELSE @PostalCode END),
		[CountryName] = (CASE WHEN (@CountryName = '''') THEN CountryName ELSE @CountryName END),
		[OrgName] = (CASE WHEN (@OrgName = '''') THEN OrgName ELSE @OrgName END),
		[OrgDescription] = (CASE WHEN (@OrgDescription = '''') THEN OrgDescription ELSE @OrgDescription END),
		UpdatedDate = @LastUpdated

	WHERE (([ID] = @ID));

	END	');
	
	PRINT 'PAL - Updating ctcsp_Get_LogViewDurations_ByProjectID'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogViewDurations_ByProjectID' )
		DROP PROCEDURE [pal].ctcsp_Get_LogViewDurations_ByProjectID
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogViewDurations_ByProjectID]
	(
		@ProjectID int
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
		SELECT
			lds.CompanyID,
			lds.ProjectID,
			lds.CentralFileName, 
			pal.LogEvent.ViewName, 
			lds.UserName,
			SUM(pal.LogEvent.EventDuration) as TotalDuration,
			SUM(pal.LogEvent.ActionCt) as TotalActions
		FROM pal.LogDocSession as lds
		INNER JOIN
			pal.LogEvent ON lds.ID = pal.LogEvent.DocSessionID
		WHERE lds.ProjectID = @ProjectID
		
		GROUP BY  
				lds.CompanyID,
				lds.ProjectID,
				lds.CentralFileName, 
				pal.LogEvent.ViewName,
				lds.UserName

	    ORDER BY 
				lds.CompanyID,
				lds.ProjectID,
				lds.CentralFileName, 
				pal.LogEvent.ViewName,
				lds.UserName
	END ');
	
	PRINT 'PAL - Updating ctcsp_Get_LogWarningSummary_ByProjectID'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogWarningSummary_ByProjectID' )
		DROP PROCEDURE [pal].ctcsp_Get_LogWarningSummary_ByProjectID
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogWarningSummary_ByProjectID]
	(
		@ProjectID int
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
		SELECT        
			pal.LogDocSession.ID, 
			pal.LogDocSession.CentralFileName, 
			pal.LogWarningSummary.Description,
			pal.LogWarningSummary.ElementIds,
			pal.LogDocSession.UserName,
			pal.LogWarningSummary.LogDateTime
		FROM pal.LogDocSession 
			INNER JOIN pal.LogWarningSummary ON pal.LogDocSession.ID = pal.LogWarningSummary.DocSessionID 
		WHERE pal.LogDocSession.ProjectID = @ProjectID

	END ');
	
    PRINT 'PAL - Updating ctcsp_Get_Crash_ByProjectID'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogCrash_ByProjectID' )
		DROP PROCEDURE [pal].ctcsp_Get_LogCrash_ByProjectID
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogCrash_ByProjectID]
	(
		@ProjectID int
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
		SELECT        
				pal.LogCrash.ID, 
				pal.LogDocSession.ProjectID,
				pal.LogCrash.DocSessionID, 
				pal.LogCrash.UserName,
				pal.LogDocSession.MachineName, 
				pal.LogCrash.CentralFileName, 
				pal.LogCrash.RevitVersion, 
				pal.LogCrash.LocalFileSize, 
				pal.LogCrash.Description,
				pal.LogCrash.LogDateTime
			FROM pal.LogCrash 
			INNER JOIN  pal.LogDocSession ON pal.LogCrash.DocSessionID = pal.LogDocSession.ID
		WHERE ProjectID = @ProjectID
		
	END ');
	
	PRINT 'PAL - Updating ctcsp_Get_Current_AddIn'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Current_AddIn' )
		DROP PROCEDURE [pal].ctcsp_Get_Current_AddIn
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Current_AddIn]
		@p_CompanyID int
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SELECT 
			pal.LogDocSession.MachineName, 
			pal.LogDocSession.RevitVersion,
			pal.LogAddIn.Name AS AppName, 
			MAX(pal.LogAddIn.LogDateTime)
		FROM pal.LogDocSession 
			INNER JOIN pal.LogAddIn 
				ON pal.LogDocSession.ID = pal.LogAddIn.DocSessionID
		WHERE pal.LogDocSession.CompanyID = @p_CompanyID
		GROUP BY 
			pal.LogDocSession.MachineName,
			pal.LogDocSession.RevitVersion, 
			pal.LogAddIn.Name
		ORDER BY 
			pal.LogDocSession.MachineName, 
			pal.LogDocSession.RevitVersion,
			pal.LogAddIn.Name
	END 
 ');
 
	PRINT 'PAL - Updating ctcsp_Get_LogElementChanges_ByProjectID'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogElementChanges_ByProjectID' )
		DROP PROCEDURE [pal].ctcsp_Get_LogElementChanges_ByProjectID
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogElementChanges_ByProjectID]
	(
		@ProjectID int
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
		SELECT        
			pal.LogDocSession.ID, 
			pal.LogDocSession.CentralFileName, 
			pal.LogElement.ElementId,
			pal.LogENUM.Description,
			pal.LogDocSession.UserName,
			pal.LogElement.LogDateTime
		FROM pal.LogDocSession 
			INNER JOIN pal.LogElement ON pal.LogDocSession.ID = pal.LogElement.DocSessionID 
			INNER JOIN pal.LogENUM ON pal.LogElement.ActionType = pal.LogENUM.EnumID
		WHERE (pal.LogENUM.EnumType = N''ElementChange'')
		AND pal.LogDocSession.ProjectID = @ProjectID

	END ');
	
	PRINT ''
	PRINT 'PAL - Updating ctcsp_Get_LogPrintJobs_ByProjectID'
			
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogPrintJobs_ByProjectID' )
		DROP PROCEDURE [pal].ctcsp_Get_LogPrintJobs_ByProjectID
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogPrintJobs_ByProjectID]
	(
		@ProjectID int
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
		SELECT        
			pal.LogDocSession.ID, 
			pal.LogDocSession.ProjectID,
			pal.LogDocSession.CentralFileName,
			pal.LogDocSession.ShortFileName, 
			pal.LogDocSession.UserName,
			pal.LogPrint.JobID,
			pal.LogPrint.Printed,
			pal.LogPrint.Failed,
			pal.LogPrint.PrintCt,
			pal.LogPrint.FailCt,
			pal.LogPrint.JobStart,
			pal.LogPrint.JobEnd
		FROM pal.LogDocSession 
			INNER JOIN pal.LogPrint ON pal.LogDocSession.ID = pal.LogPrint.DocSessionID 
		WHERE pal.LogDocSession.ProjectID = @ProjectID

	END ');
	
	PRINT 'PAL - Creating ctcsp_Get_OpenLogSessions_ByDate'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_OpenLogSessions_ByDate' )
		DROP PROCEDURE [pal].ctcsp_Get_OpenLogSessions_ByDate
	
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_OpenLogSessions_ByDate]
	(
	    @p_CompanyID int,
	    @pFenceStart DATETIME,
		@FenceRange nvarchar(7)
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		DECLARE @pFenceEnd DATETIME

		SET @FenceRange = LOWER(@FenceRange);

		IF @FenceRange = ''minute'' 
			BEGIN
			SET @pFenceStart = dateadd(minute, datediff(minute, 0, @pFenceStart),0)
			SET @pFenceEnd = dateadd(minute, (datediff(minute, 0, @pFenceStart) + 1),0);
			END
		ELSE IF @FenceRange = ''hour''
			BEGIN
			SET @pFenceStart = dateadd(hour, datediff(hour, 0, @pFenceStart),0)
			SET @pFenceEnd = dateadd(hour, (datediff(hour, 0, @pFenceStart) + 1),0);
			END
		ELSE IF @FenceRange = ''day''
			BEGIN
			SET @pFenceStart = dateadd(day, datediff(day, 0, @pFenceStart),0)
			SET @pFenceEnd = dateadd(day, (datediff(day, 0, @pFenceStart) + 1),0);
			END
		ELSE IF @FenceRange = ''week''
			BEGIN
			SET @pFenceStart = dateadd(week, datediff(week, 0, @pFenceStart),0)
			SET @pFenceEnd = dateadd(week, (datediff(week, 0, @pFenceStart) + 1),0);
			END
		ELSE IF @FenceRange = ''month''
			BEGIN
			SET @pFenceStart = dateadd(month, datediff(month, 0, @pFenceStart),0)
			SET @pFenceEnd = dateadd(month, (datediff(month, 0, @pFenceStart) + 1),0);
			END
		ELSE
			BEGIN
			SET @pFenceStart =  dateadd(second, -3, GETUTCDATE());
			SET @pFenceEnd = dateadd(second, 3, GETUTCDATE());
			END

		SELECT [ID]
		  ,[CompanyID]
		  ,[UserName]
		  ,[MachineName]
		  ,[RevitVersion]
		  ,[StartDateTime]
		  ,[EndDateTime]
		FROM [pal].[LogSession]

		-- BETWEEN DATES
		WHERE CompanyID =  @p_CompanyID  
	    AND StartDateTime < @pFenceEnd
		AND (EndDateTime > @pFenceStart
		OR EndDateTime IS NULL)
		ORDER BY StartDateTime
	
	END ');
	
	PRINT 'PAL - Creating ctcsp_Get_OpenLogSessions_Current'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_OpenLogSessions_Current' )
		DROP PROCEDURE [pal].ctcsp_Get_OpenLogSessions_Current
	
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_OpenLogSessions_Current]
	(
		@p_CompanyID int
	)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		DECLARE @pFenceEnd DATETIME
		DECLARE @pFenceStart DATETIME
			
		SET @pFenceStart =  dateadd(second, -3, GETUTCDATE());
		SET @pFenceEnd = dateadd(second, 3, GETUTCDATE());

		SELECT [ID]
		  ,[CompanyID]
		  ,[UserName]
		  ,[MachineName]
		  ,[RevitVersion]
		  ,[StartDateTime]
		  ,[EndDateTime]
		FROM [pal].[LogSession]

		-- BETWEEN DATES
		WHERE CompanyID =  @p_CompanyID  
	    AND  StartDateTime < @pFenceEnd
		AND (EndDateTime > @pFenceStart
		OR EndDateTime IS NULL)
		ORDER BY StartDateTime
	
	END ');
	
	PRINT 'PAL - Creating ctcsp_Get_CompanySubscription_ByGUID'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_CompanySubscription_ByGUID' )
		DROP PROCEDURE [pal].ctcsp_Get_CompanySubscription_ByGUID
	
	EXEC('
	CREATE PROCEDURE [pal].[ctcsp_Get_CompanySubscription_ByGUID]
	(
		@CompanyID uniqueidentifier
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
		SELECT 
			CAST(c.ID AS nvarchar(255)) As CompanyId, 
			s.SerialNumber,
			Convert(varchar, s.EndDate, 21) As EndDate
		FROM acct.Company AS c
		INNER JOIN acct.Subscription AS s ON s.CompanyID = c.ID
		WHERE s.ProductID = 1
		AND c.GUID = @CompanyID
	END ');
	
	PRINT 'PAL - Creating ctcsp_Get_CompanySubscription_ByID'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_CompanySubscription_ByID' )
		DROP PROCEDURE [pal].ctcsp_Get_CompanySubscription_ByID
	
	EXEC('
	CREATE PROCEDURE [pal].[ctcsp_Get_CompanySubscription_ByID]
	(
		@CompanyID int
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
		SELECT 
			CAST(c.ID AS nvarchar(255)) As CompanyId, 
			s.SerialNumber,
			Convert(varchar, s.EndDate, 21) As EndDate
		FROM acct.Company AS c
		INNER JOIN acct.Subscription AS s ON s.CompanyID = c.ID
		WHERE s.ProductID = 1
		AND c.ID = @CompanyID
	END ');
	
	begin try
		DROP PROCEDURE [dbo].[ctcsp_Get_Projects]
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Projects] 
	
	AS
	BEGIN
			
		SET NOCOUNT ON;

		SELECT 
				[Id]
				,[Project]
				,[Project Number]
				,[Project Name]
				,[Client Name]
				,[Issue Date]
				,[Days Until Issue]
				,[Office]
				,[BuildingName]
				,[ClientName]
				,[StreetAddress]
				,[StreetAddress2]
				,[StreetAddress3]
				,[ProjectPhase]
				,[Author]
				,[City]
				,[StateOrProvince]
				,[PostalCode]
				,[CountryName]
				,[OrgName]
				,[OrgDescription]
				,AddedDate
		FROM pal.ctcvw_Projects 
		ORDER BY [Project Number]

	END ');
	
	
	
	PRINT ''
	PRINT 'End PAL stored procedures'
			
	PRINT ''
	PRINT 'Begin PAL PowerBI stored procedures'
	
	PRINT ''
	
	PRINT 'PAL - Updating ctcsp_Get_OpenLogSessions_ByNamedDateRange'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_OpenLogSessions_ByNamedDateRange' )
		DROP PROCEDURE [dbo].ctcsp_Get_OpenLogSessions_ByNamedDateRange
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_OpenLogSessions_ByNamedDateRange]
	(
		@p_NamedDateRange nvarchar(7)
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		DECLARE @pFenceStart DATETIME
		DECLARE @pFenceEnd DATETIME

		SET @pFenceStart =  dateadd(second, -3, GETUTCDATE());

		SET @p_NamedDateRange = LOWER(@p_NamedDateRange);
		
		IF @p_NamedDateRange = ''ytd'' 
			BEGIN
			SET @pFenceStart = dateadd(year, datediff(year, 0, @pFenceStart),0)
			SET @pFenceEnd = dateadd(year, (datediff(year, 0, @pFenceStart) + 1),0);
			END
		ELSE IF @p_NamedDateRange = ''mtd''
			BEGIN
			SET @pFenceStart =dateadd(month, datediff(month, 0, @pFenceStart),0)
			SET @pFenceEnd =dateadd(month, (datediff(month, 0, @pFenceStart) + 1),0);
			END
		ELSE IF @p_NamedDateRange = ''today''
			BEGIN
			SET @pFenceStart = dateadd(day, datediff(day, 0, @pFenceStart),0)
			SET @pFenceEnd = dateadd(day, (datediff(day, 0, @pFenceStart) + 1),0);
			END
		ELSE IF @p_NamedDateRange = ''last30''
			BEGIN
			SET @pFenceEnd = dateadd(day, datediff(day, 0, @pFenceStart),0)
			SET @pFenceStart = dateadd(day, (datediff(day, 0, @pFenceStart) - 30 ),0);
			
			END
		ELSE IF @p_NamedDateRange = ''last60''
			BEGIN
			SET @pFenceEnd = dateadd(day, datediff(day, 0, @pFenceStart),0)
			SET @pFenceStart = dateadd(day, (datediff(day, 0, @pFenceStart) - 60),0);
			
			END

		ELSE IF @p_NamedDateRange = ''last90''
			BEGIN
			SET @pFenceEnd = dateadd(day, datediff(day, 0, @pFenceStart),0)
			SET @pFenceStart = dateadd(day, (datediff(day, 0, @pFenceStart) - 90),0);
			
			END
		ELSE IF @p_NamedDateRange = ''last180''
			BEGIN
			SET @pFenceEnd = dateadd(day, datediff(day, 0, @pFenceStart),0)
			SET @pFenceStart = dateadd(day, (datediff(day, 0, @pFenceStart) -180 ),0);
			
			END
		ELSE
			BEGIN
			SET @pFenceStart =  dateadd(second, -3, GETUTCDATE());
			SET @pFenceEnd = dateadd(second, 3, GETUTCDATE());
			END

		SELECT [ID]
		  ,[CompanyID]
		  ,[UserName]
		  ,[MachineName]
		  ,[RevitVersion]
		  ,[StartDateTime]
		  ,[EndDateTime]
		FROM [pal].[LogSession]

		-- BETWEEN DATES
		WHERE StartDateTime < @pFenceEnd
		AND (EndDateTime > @pFenceStart
		OR EndDateTime IS NULL)
		ORDER BY StartDateTime
		
	END ');
	
	PRINT 'PAL - Updating ctcsp_Get_LogSessions_ByNamedDateRange'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogSessions_ByNamedDateRange' )
		DROP PROCEDURE [dbo].ctcsp_Get_LogSessions_ByNamedDateRange
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogSessions_ByNamedDateRange]
	(
		@p_NamedDateRange nvarchar(7)
    )
	AS
	BEGIN
	-- SET NOCOUNT ON is added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @pFenceStart DATETIME

	SET @pFenceStart =  dateadd(second, -3, GETUTCDATE());

	SET @p_NamedDateRange = LOWER(@p_NamedDateRange);
	
    IF @p_NamedDateRange = ''ytd''
		BEGIN
		SET @pFenceStart = dateadd(year, datediff(year, 0, @pFenceStart),0)
		END
    ELSE IF @p_NamedDateRange = ''mtd''
		BEGIN
		SET @pFenceStart =dateadd(month, datediff(month, 0, @pFenceStart),0)
		END
	ELSE IF @p_NamedDateRange = ''today''
		BEGIN
		SET @pFenceStart = dateadd(day, datediff(day, 0, @pFenceStart),0)
		END
	ELSE IF @p_NamedDateRange = ''last30''
		BEGIN
	    SET @pFenceStart = dateadd(day, (datediff(day, 0, @pFenceStart) - 30 ),0);
		END
	ELSE IF @p_NamedDateRange = ''last60''
	    BEGIN
	    SET @pFenceStart = dateadd(day, (datediff(day, 0, @pFenceStart) - 60),0);
		END
	ELSE IF @p_NamedDateRange = ''last90''
	    BEGIN
	    SET @pFenceStart = dateadd(day, (datediff(day, 0, @pFenceStart) - 90),0);
		END
	ELSE IF @p_NamedDateRange = ''last180''
	    BEGIN
	    SET @pFenceStart = dateadd(day, (datediff(day, 0, @pFenceStart) -180 ),0);
		END
	ELSE
		BEGIN
		SET @pFenceStart =  dateadd(second, -3, GETUTCDATE());
		END

	SELECT [ID]
      ,[CompanyID]
      ,[UserName]
      ,[MachineName]
	  ,[RevitVersion]
      ,[StartDateTime]
      ,[EndDateTime]
	FROM [pal].[LogSession]
	WHERE StartDateTime > @pFenceStart
	ORDER BY StartDateTime
	
	END ');
    
			   
	PRINT 'PAL - Updating ctcsp_Get_STCs_ByNamedDateRange'
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_STCs_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_STCs_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_STCs_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT [ID] AS Id
			,[DocSessionID] As DocSessionId
			,[EventDateTime] AS StcDateTime
			,[EventDuration] AS StcDuration
			FROM pal.LogEvent ''

			Set @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''EventDateTime'');

			IF @where = ''''
				SET  @Where = ''WHERE (EventName = N''''SyncComplete'''')''
			ELSE
				SET @where = @where + '' AND (EventName = N''''SyncComplete'''')''

		EXEC(@sql + @where + '' ORDER BY EventDateTime'');
	END ');

	PRINT 'PAL - Updating ctcsp_Get_CentralFiles_ByNamedDateRange'
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_CentralFiles_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_CentralFiles_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_CentralFiles_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
		SET NOCOUNT ON;
		DECLARE @sql varchar(2300)
		DECLARE @AndClause varchar(1000)

		SET @sql = 
			''SELECT   
			Data.ID As Id, 
			ProjectID As ProjectId, 
			asset.Project.ProjectNumber AS [Project Number], 
			asset.Project.ProjectName AS [Project Name], 
			asset.Project.ClientName AS [Client Name], 
			UserName AS Contributor, 
			Server, 
			CentralFileName AS [Central File], 
			ShortFileName AS [File Name], 
			LocalFileName AS [Local File], 
			LocalFileSize / 1048576.0 AS [File Size (MB)], 
			RevitVersion AS [Revit Version], 
			IsAudit AS Auditing, 
			DocDateTime AS Opened, 
			STCDateTime AS [Last Saved], 
			LoadTime AS [Open Duration (Sec)], 
			STCDuration AS [STC Duration (Sec)], 
			SessionHours AS [Session Hours], 
			GroupCt AS Groups, 
			InPlaceCt AS [In-place Families], 
			UnPlacedRoomCt AS [Unplaced Rooms], 
			UnenclosedRoomCt AS [Unenclosed Rooms], 
			PlacedRoomCt AS Rooms, 
			UnPlacedSpaceCt AS [Unplaced Spaces], 
			UnenclosedSpaceCt AS [Unenclosed Spaces], 
			PlacedSpaceCt AS Spaces, 
			ViewCt AS Views, 
			PhaseCt AS Phases, 
			DesOptCt AS [Design Options], 
			WorksetCt AS Worksets,
			Data.WorksetEditCt AS EditableWorksets,
			WorksetOpenCt AS OpenWorksets, 
			FamilyCt AS Families, 
			InstanceCt AS [Family Instances], 
			UnplacedFamilyCt AS [Unplaced Families],
			MaterialCt AS Materials, 
			ViewFilterCt AS [View Filters], 
			LevelCt AS Levels, ElemAddedCt AS Added, 
			ElemDeletedCt AS Deleted, 
			ElemModifiedCt AS Modified, 
			ElemAddedCt + ElemDeletedCt + ElemModifiedCt AS [Edited Items], 
			WarningCt AS Warnings, 
			MachineName,
			BasePoint,
			SurveyPoint,
			AngleToTrueNorth,
			CONVERT(DateTime,CONVERT(Date, DocDateTime, 101)) AS DayOpened 

			FROM (pal.LogDocSession AS Data INNER JOIN asset.Project ON ProjectID = asset.Project.ID) 
			WHERE ([DocDateTime] =
				(SELECT MAX([DocDateTime]) AS Expr1
					FROM     pal.LogDocSession AS LogDocSession_1
						WHERE ([CentralFileName] = Data.[CentralFileName]) AND (ProjectID = Data.ProjectID) AND (STCDuration > 0)) ''
				

			SET @AndClause = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''DocDateTime'');
			EXEC (@sql + @AndClause  + '' AND (ProjectID IS NOT NULL) );'');
			  
		END ');

				
				
	PRINT 'PAL - Updating ctcsp_Get_Current_Links_ByNamedDateRange'
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Current_Links_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Current_Links_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Current_Links_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
			
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @and varchar(1000)

		SET @sql = 
			''SELECT 
				pal.LogLink.DocSessionID As DocSessionId, 
				ProjectID As ProjectId, 
				CentralFileName AS [Central File], 
				ShortFileName AS [File Name], 
				pal.LogLink.LinkPath AS [Link Path], 
				pal.LogLink.LinkShortFileName AS [Link Filename], 
				pal.LogLink.LinkType AS [Link Type], 
				pal.LogLink.LinkStatus AS [Link Status], 
				pal.LogLink.UserName, 
				pal.LogLink.LinksDateTime
				FROM pal.LogDocSession AS Data INNER JOIN
				pal.LogLink ON Data.ID = pal.LogLink.DocSessionID

				WHERE ([DocDateTime] =
						(SELECT MAX([DocDateTime]) AS Expr1
							FROM  pal.LogDocSession AS LogDocSession_1
								WHERE ([CentralFileName] = Data.[CentralFileName]) 
								AND (ProjectID = Data.ProjectID) 
								AND (ProjectID IS NOT NULL)
								AND (STCDuration > 0)
							)
						) ''

			Set @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''DocDateTime'');

			EXEC(@sql + @and + '' Order by LinksDateTime'');

	END ');

				
				
	PRINT 'PAL - Updating ctcsp_Get_Current_Machines'
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Current_Machines
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Current_Machines
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Current_Machines]
	AS
	BEGIN
			
	SET NOCOUNT ON;
		
	DECLARE @sql varchar(1000)

	SET @sql = 
		''SELECT Distinct    
			DocSessionID As DocSessionId, 
			MachineName, 
			IPAddress, 
			OperatingSystem, 
			CPU, 
			RAM, 
			RAM_Slots, 
			Video, 
			HDD, 
			MAC, 
			LogDateTime AS [Date Created]
		FROM pal.LogMachine AS Data
		WHERE (LogDateTime = 
			(SELECT MAX(LogDateTime) AS Expr1
				FROM pal.LogMachine
					WHERE (MachineName = Data.MachineName))) 
		ORDER BY MachineName''

		EXEC(@sql);

	END ');

	
				
				
	PRINT 'PAL - Updating ctcsp_Get_Current_Machines_ByNamedDateRange'

	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Current_Machines_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Current_Machines_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Current_Machines_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
				
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @and varchar(1000)

		SET @sql = 
			''SELECT Distinct      
				DocSessionID As DocSessionId, 
				MachineName, 
				IPAddress, 
				OperatingSystem, 
				CPU, 
				RAM, 
				RAM_Slots, 
				Video, 
				HDD, 
				MAC, 
				LogDateTime AS [Date Created]
			FROM pal.LogMachine AS Data
			WHERE (LogDateTime = 
				(SELECT MAX(LogDateTime) AS Expr1
					FROM pal.LogMachine
						WHERE (MachineName = Data.MachineName))) ''

			SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''LogDateTime'');

			EXEC(@sql + @and + '' Order by MachineName'');

		END ');

				
				
	PRINT 'PAL - Updating ctcsp_Get_Current_Views_ByNamedDateRange'
		
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Current_Views_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Current_Views_ByNamedDateRange
	end try
	begin catch
	end catch		
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Current_Views_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @and varchar(1000)

		SET @sql = 
			''SELECT        
				pal.LogViewType.DocSessionID As DocSessionId, 
				ProjectID As ProjectId, 
				CentralFileName AS [Central File], 
				ShortFileName AS [File Name],  
				pal.LogViewType.ViewTypeName AS [View Types], 
				pal.LogViewType.ViewCt AS Views, 
				pal.LogViewType.ViewDateTime AS [Date Created]
				FROM pal.LogDocSession AS Data
				INNER JOIN pal.LogViewType ON Data.ID = pal.LogViewType.DocSessionID
				WHERE ([DocDateTime] =
					(SELECT MAX([DocDateTime]) AS Expr1
						FROM pal.LogDocSession AS LogDocSession_1
							WHERE ([CentralFileName] = Data.[CentralFileName]) AND (ProjectID = Data.ProjectID) 
							AND (ProjectID IS NOT NULL) 
							AND (STCDuration > 0) 
					)) ''

			SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');
			EXEC(@sql + @and + '' ORDER BY [Date Created]'');

		END ');

				
				
	PRINT 'PAL - Updating ctcsp_Get_Current_Warnings_ByNamedDateRange'
			
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Current_Warnings_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Current_Warnings_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Current_Warnings_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
			
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @and varchar(1000)

		SET @sql = 
			''SELECT
				pal.LogWarning.DocSessionID As DocSessionId, 
				ProjectID As ProjectId, 
				CentralFileName AS [Central File], 
				ShortFileName AS [File Name],
				pal.LogWarning.WarningDateTime AS [Date Created], 
				pal.LogWarning.WarningId, 
				pal.LogWarning.Severity, 
				pal.LogWarning.Description, 
				pal.LogWarning.ElementId, 
				pal.LogWarning.ElementName, 
				pal.LogWarning.LevelName AS [Level Name], 
				pal.LogWarning.Workset
			FROM pal.LogDocSession AS Data
			INNER JOIN pal.LogWarning ON Data.ID = pal.LogWarning.DocSessionID
			WHERE ([DocDateTime] =
						(SELECT MAX([DocDateTime]) AS Expr1
							FROM pal.LogDocSession AS LogDocSession_1
								WHERE (([CentralFileName] = Data.[CentralFileName]) 
								AND (ProjectID = Data.ProjectID) 
								AND (ProjectID IS NOT NULL)
								AND (STCDuration > 0)
								)
						)
					) ''

			SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');
				
			EXEC(@sql + @and +  '' ORDER BY [Date Created]'');

		END ');

				
	PRINT 'PAL - Drop ctcsp_Get_LogChanges_ByNamedDateRange'

	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogChanges_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogChanges_ByNamedDateRange
	end try
	begin catch
	end catch	

	PRINT 'PAL - Updating ctcsp_Get_LogDocSessions_ByNamedDateRange'

	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogDocSessions_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogDocSessions_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogDocSessions_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
				
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT [ID] As Id
			,[ProjectID] As ProjectId
			,[UserName]
			,[Server]
			,[CentralFileName]
			,[ShortFileName]
			,[LocalFileName]
			,[LocalFileSize]
			,[RevitVersion]
			,[IsAudit]
			,[DocDateTime]
			,[LoadTime]
			,[STCDuration]
			,[STCDateTime]
			,[SessionHours]
			,[PhaseCt]
			,[DesOptCt]
			,[WorksetCt]
			,[WorksetEditCt]
			,[WorksetOpenCt]
			,[ViewCt]
			,[GroupCt]
			,[FamilyCt]
			,[InstanceCt]
			,[UnplacedFamilyCt]
			,[InPlaceCt]
			,[UnPlacedRoomCt]
			,[UnenclosedRoomCt]
			,[PlacedRoomCt]
			,[UnPlacedSpaceCt]
			,[UnenclosedSpaceCt]
			,[PlacedSpaceCt]
			,[MaterialCt]
			,[ViewFilterCt]
			,[LevelCt]
			,[ElemAddedCt]
			,[ElemDeletedCt]
			,[ElemModifiedCt]
			,[WarningCt]
			,[HasClosed]
			,[MachineName]
			,[BasePoint]
			,[SurveyPoint]
			,[AngleToTrueNorth]
			FROM pal.LogDocSession ''

			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''DocDateTime'');

			EXEC(@sql + @where  + '' ORDER BY DocDateTime'');

	END ');

	PRINT 'PAL - Updating ctcsp_Get_LogEvents_ByNamedDateRange'

	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogEvents_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogEvents_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogEvents_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
			
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
		''SELECT [ID] As Id
			,[DocSessionID] As DocSessionId
			,[EventId]
			,[EventType]
			,[EventName]
			,[ViewName]
			,[OpenViewCt]
			,[EventDateTime]
			,[EventDuration]
			FROM pal.LogEvent ''

			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''EventDateTime'');

			EXEC(@sql + @where  + '' ORDER BY EventDateTime'');
	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Get_LogLinks_ByNamedDateRange'
			
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogLinks_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogLinks_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogLinks_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
				
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT [ID] As Id
			,[DocSessionID] As DocSessionId
			,[LinkPath]
			,[LinkShortFileName]
			,[LinkType]
			,[LinkStatus]
			,[UserName]
			,[LinksDateTime]
			,x as CheckVal
			FROM pal.LogLink ''

			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''LinksDateTime'');

			EXEC(@sql + @where  + '' ORDER BY LinksDateTime'');

	END');

			
			
	PRINT 'PAL - Updating ctcsp_Get_LogMachines_ByNamedDateRange'
			
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogMachines_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogMachines_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogMachines_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
		AS
		BEGIN
			SET NOCOUNT ON;
			
			DECLARE @sql varchar(1000)
			DECLARE @where varchar(1000)

			SET @sql = 
				''SELECT [ID] As Id
				,[DocSessionID] As DocSessionId
				,[ProcessorId]
				,[MachineName]
				,[MAC]
				,[OperatingSystem]
				,[HDD]
				,[Motherboard]
				,[Bios]
				,[RAM]
				,[RAM_Slots]
				,[CPU]
				,[Video]
				,[LogDateTime]
				,[IPAddress]
				FROM FROM pal.ctcvw_Machines ''

				SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''LogDateTime'');

				EXEC(@sql + @where  + '' ORDER BY LogDateTime'');

		END ');

				
				
	PRINT 'PAL - Updating ctcsp_Get_LogSummaries_ByNamedDateRange'
		
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogSummaries_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogSummaries_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogSummaries_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
				
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT [ID] As Id
			,[DocSessionID] As DocSessionId
			,[EventId]
			,[GroupCt]
			,[InPlaceCt]
			,[UnPlacedRoomCt]
			,[UnenclosedRoomCt]
			,[PlacedRoomCt]
			,[ViewCt]
			,[PhaseCt]
			,[DesOptCt]
			,[WorksetCt]
			,[FamilyCt]
			,[InstanceCt]
			,[MaterialCt]
			,[ViewFilterCt]
			,[SummaryDateTime]
			,[UnplacedFamilyCt]
			,[LevelCt]
			,[WarningCt]
			FROM pal.LogSummary ''

			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''SummaryDateTime'');

			EXEC(@sql + @where  + '' ORDER BY SummaryDateTime'');

		END ');

				
				
	PRINT 'PAL - Updating ctcsp_Get_LogViewTypes_ByNamedDateRange'
	
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogViewTypes_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogViewTypes_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogViewTypes_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
				
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT [ID] As Id
			,[DocSessionID] As DocSessionId
			,[ViewTypeName]
			,[ViewCt]
			,[ViewDateTime]
			,x as CheckVal
			FROM pal.LogViewType ''

			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''ViewDateTime'');

			EXEC(@sql + @where  + '' ORDER BY ViewDateTime'');

	END ');

		
	PRINT 'PAL - Updating ctcsp_Get_LogWarnings_ByNamedDateRange'

	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogWarnings_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogWarnings_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogWarnings_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT [ID] As Id
			,[DocSessionID] As DocSessionId
			,[Severity]
			,[Description]
			,[ElementId]
			,[ElementName]
			,[LevelName]
			,[Workset]
			,[WarningDateTime]
			, x as CheckVal
			,[WarningId]
			FROM pal.ctcvw_Warnings ''

			Set @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''WarningDateTime'');

			EXEC(@sql + @where  + '' ORDER BY WarningDateTime'');

	END ');

				
				
	PRINT 'PAL - Updating ctcsp_Get_Session_Links_ByNamedDateRange'
			
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Session_Links_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Session_Links_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Session_Links_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @and varchar(1000)

		SET @sql = 
			''SELECT        
				Data.ID AS DocSessionId, 
				[STCDateTime] AS [Date Created], 
				pal.LogLink.LinkPath AS [Link Path], 
				pal.LogLink.LinkShortFileName AS [Link Filename], 
				pal.LogLink.LinkType AS [Link Type], 
				pal.LogLink.LinkStatus AS [Link Status]
			FROM pal.LogDocSession AS Data 
			INNER JOIN pal.LogLink ON Data.ID = pal.LogLink.DocSessionID
			WHERE ([STCDateTime] =
				(SELECT MAX([STCDateTime]) AS Expr1
					FROM pal.LogDocSession AS ctcvw_Sessions_1
						WHERE ((ID = Data.ID) 
						AND (ProjectID IS NOT NULL) 
						AND (STCDuration > 0))
					)
				) ''

			SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[STCDateTime]'');

			EXEC(@sql + @and + '' ORDER BY [Date Created]'');

		END ' );
				
				
	PRINT 'PAL - Updating ctcsp_Get_Session_Machines_ByNamedDateRange'
		
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Session_Machines_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Session_Machines_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Session_Machines_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN

		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @and varchar(1000)

		SET @sql = 
			''SELECT        
				pal.ctcvw_Machines.DocSessionID As DocSessionId, 
				pal.ctcvw_Machines.MachineName, 
				pal.ctcvw_Machines.IPAddress, 
				pal.ctcvw_Machines.OperatingSystem, 
				pal.ctcvw_Machines.CPU, 
				pal.ctcvw_Machines.RAM, 
				pal.ctcvw_Machines.RAM_Slots, 
				pal.ctcvw_Machines.Video, 
				pal.ctcvw_Machines.HDD, 
				pal.ctcvw_Machines.MAC, 
				pal.ctcvw_Machines.LogDateTime AS [Date Created]
			FROM pal.LogDocSession 
			INNER JOIN pal.ctcvw_Machines ON pal.LogDocSession.ID = pal.ctcvw_Machines.DocSessionID
			WHERE ((pal.LogDocSession.ProjectID IS NOT NULL)
			AND (STCDuration > 0)) ''

		SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');	
			
		EXEC(@sql + @and + '' ORDER BY [Date Created]'');

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Get_Session_Views_ByNamedDateRange'
		
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Session_Views_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Session_Views_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Session_Views_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @and varchar(1000)

		SET @sql = 
			''SELECT        
			Data.ID AS DocSessionId, 
			Data.[STCDateTime] AS [Date Created], 
			pal.LogViewType.ViewTypeName AS [View Types], 
			pal.LogViewType.ViewCt AS Views
			FROM pal.LogDocSession AS Data 
			INNER JOIN pal.LogViewType ON Data.ID = pal.LogViewType.DocSessionID
			WHERE (Data.[STCDateTime] =
					(SELECT MAX([STCDateTime]) AS Expr1
						FROM pal.LogDocSession AS ctcvw_Sessions_1
						WHERE   ((ID = Data.ID)
						AND (ProjectID IS NOT NULL)
						AND (STCDuration > 0))
					)
				) ''

			Set @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');
				
			EXEC(@sql + @and + '' ORDER BY [Date Created]'');

	END ');
				
				
				
	PRINT 'PAL - Updating ctcsp_Get_Session_Warnings_ByNamedDateRange'
			
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Session_Warnings_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Session_Warnings_ByNamedDateRange
	end try
	begin catch
	end catch	
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Session_Warnings_ByNamedDateRange]
	(
		@p_NamedDateRange nvarchar(7)
	)
	AS
	BEGIN
				
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @and varchar(1000)

		SET @sql = 
			''SELECT 
			pal.LogWarning.DocSessionID As DocSessionId, 
			pal.LogWarning.Severity, 
			pal.LogWarning.Description, 
			pal.LogWarning.ElementId, 
			pal.LogWarning.ElementName, 
			pal.LogWarning.LevelName AS [Level Name], 
			pal.LogWarning.Workset, 
			pal.LogWarning.WarningDateTime AS [Date Created]
			FROM pal.LogDocSession As Data
			INNER JOIN pal.LogWarning ON Data.ID = pal.LogWarning.DocSessionID
			WHERE (Data.[STCDateTime] =
						(SELECT MAX([STCDateTime]) AS Expr1
							FROM pal.LogDocSession AS ctcvw_Sessions_1
							WHERE   ((ID = Data.ID)
							AND (ProjectID IS NOT NULL)
							AND (STCDuration > 0))
						)
					)  ''

			SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');
			EXEC(@sql + @and + '' ORDER BY [Date Created]'');

	END ');

			
			
	PRINT 'PAL - Updating ctcsp_Get_Sessions_ByNamedDateRange'
		
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Sessions_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Sessions_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Sessions_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1900)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT        
				LogDocSession.ID As Id, 
				ProjectID as projectId, 
				Project.ProjectNumber AS [Project Number], 
				Project.ProjectName AS [Project Name], 
				Project.ClientName AS [Client Name], 
				UserName AS Contributor, 
				Server, 
				CentralFileName AS [Central File], 
				ShortFileName AS [File Name], 
				LocalFileName AS [Local File], 
				LocalFileSize / 1048576.0 AS [File Size (MB)], 
				RevitVersion AS [Revit Version], 
				IsAudit AS Auditing, 
				DocDateTime AS Opened, 
				STCDateTime AS [Last Saved], 
				LoadTime AS [Open Duration (Sec)], 
				STCDuration AS [STC Duration (Sec)], 
				SessionHours AS [Session Hours], 
				GroupCt AS Groups, 
				InPlaceCt AS [In-place Families], 
				UnPlacedRoomCt AS [Unplaced Rooms], 
				UnenclosedRoomCt AS [Unenclosed Rooms], 
				PlacedRoomCt AS Rooms, 
				UnPlacedSpaceCt AS [Unplaced Spaces], 
				UnenclosedSpaceCt AS [Unenclosed Spaces], 
				PlacedSpaceCt AS Spaces,
				ViewCt AS Views, 
				PhaseCt AS Phases, 
				DesOptCt AS [Design Options], 
				WorksetCt AS Worksets, 
				WorksetEditCt AS EditableWorksets,
				WorksetOpenCt AS OpenWorksets, 
				FamilyCt AS Families, 
				InstanceCt AS [Family Instances], 
				UnplacedFamilyCt AS [Unplaced Families],
				MaterialCt AS Materials, 
				ViewFilterCt AS [View Filters], 
				LevelCt AS Levels, ElemAddedCt AS Added, 
				ElemDeletedCt AS Deleted, 
				ElemModifiedCt AS Modified, 
				ElemAddedCt + ElemDeletedCt + 
				ElemModifiedCt AS [Edited Items], 
				WarningCt AS Warnings,
				HasClosed As [Session Closed], 
				MachineName,
				BasePoint,
				SurveyPoint,
				AngleToTrueNorth,
				CONVERT(DateTime,CONVERT(Date, DocDateTime, 101)) AS DayOpened
			
				FROM pal.LogDocSession INNER JOIN asset.Project ON ProjectID = asset.Project.ID ''
				
			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''DocDateTime'');
			EXEC(@sql + @where + '' AND (ProjectID IS NOT NULL) AND (STCDuration > 0);'');
	END ');
			
	--TODO: FIX THIS!!!	
	PRINT 'PAL - Updating ctcsp_Get_LogViewDurations_ByNamedDateRange'
			
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogViewDurations_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogViewDurations_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogViewDurations_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)

	AS
	BEGIN
	-- SET NOCOUNT ON is added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
			
	DECLARE @sql varchar(1000)
	DECLARE @and varchar(1000)

	SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');
	SET @sql = 
			''SELECT
			lds.ID as Id,
			lds.ProjectID,
			lds.CentralFileName,
			lds.ShortFileName,
			lds.UserName,
			pal.LogEvent.ViewName, 
			SUM(pal.LogEvent.EventDuration) as TotalDuration,
			SUM(pal.LogEvent.ActionCt) as TotalActions
			FROM pal.LogDocSession as lds
			INNER JOIN
			pal.LogEvent ON lds.ID = pal.LogEvent.DocSessionID
			WHERE pal.LogEvent.EventName = ''''ViewInit'''' ''

	EXEC(@sql + @and + '' GROUP BY lds.ID,lds.ProjectID, lds.CentralFileName, lds.ShortFileName, ViewName, lds.UserName 
			ORDER BY lds.ProjectID, lds.CentralFileName, ViewName, lds.UserName'');

	END 
 ');
	PRINT 'PAL - Updating ctcsp_Get_LogCrash_ByNamedDateRange'
			
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogCrash_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogCrash_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogCrash_ByNamedDateRange]
	(
		@p_NamedDateRange nvarchar(7)
    )
	AS
	BEGIN
	-- SET NOCOUNT ON is added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
			
	DECLARE @sql varchar(1000)
	DECLARE @where varchar(1000)

	SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''[LogDateTime]'');
	SET @sql = 
			''SELECT        
				pal.LogCrash.ID, 
				pal.LogDocSession.ProjectID,
				pal.LogCrash.DocSessionID, 
				pal.LogCrash.UserName,
				pal.LogDocSession.MachineName, 
				pal.LogCrash.CentralFileName, 
				pal.LogCrash.RevitVersion, 
				pal.LogCrash.LocalFileSize, 
				pal.LogCrash.Description,
				pal.LogCrash.LogDateTime
			FROM pal.LogCrash 
			INNER JOIN  pal.LogDocSession ON pal.LogCrash.DocSessionID = pal.LogDocSession.ID ''
  
	EXEC(@sql + @where);

	END 
 ');
 
	PRINT 'PAL - Updating ctcsp_Get_Current_AddIns'
	
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_Current_AddIns
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_Current_AddIns
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Current_AddIns]
	
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SELECT
			 pal.LogAddIn.ID AS ID,
			 pal.LogAddIn.Name, 
			 Data.DocDateTime As LogDateTime,
			 Data.ID AS DocSessionID
				FROM pal.LogDocSession AS Data INNER JOIN
				pal.LogAddIn ON Data.ID = pal.LogAddIn.DocSessionID
				WHERE([DocDateTime] =
				(SELECT MAX([DocDateTime]) AS Expr1
					FROM pal.LogDocSession AS LogDocSession_1
					   WHERE(ProjectID = Data.ProjectID)
						AND(MachineName = Data.MachineName)
						AND(RevitVersion = Data.RevitVersion)))
			ORDER BY 
			Data.MachineName, 
			Data.RevitVersion, 
			pal.LogAddIn.Name
	END 
 ');
 
 PRINT 'PAL - Updating ctcsp_Get_LogAddIns_ByNamedDateRange'
	
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogAddIns_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogAddIns_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogAddIns_ByNamedDateRange]
	(
		@p_NamedDateRange nvarchar(7)
    )
	AS
	BEGIN
	-- SET NOCOUNT ON is added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
			
	DECLARE @sql varchar(1000)
	DECLARE @where varchar(1000)

	SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''[LogDateTime]'');
	SET @sql = 
			''SELECT 
				pal.LogAddIn.ID, 
				pal.LogDocSession.ProjectID, 
				pal.LogAddIn.DocSessionID, 
				pal.LogDocSession.UserName, 
				pal.LogDocSession.MachineName, 
				pal.LogDocSession.RevitVersion,
				pal.LogAddIn.Name AS AppName, 
				pal.LogAddIn.LogDateTime
			FROM pal.LogDocSession 
				INNER JOIN pal.LogAddIn 
					ON pal.LogDocSession.ID = pal.LogAddIn.DocSessionID ''
			
  
	EXEC(@sql + @where + '' ORDER BY pal.LogDocSession.ProjectID, 
				pal.LogAddIn.DocSessionID, 
				pal.LogDocSession.UserName, 
				pal.LogDocSession.MachineName,
				pal.LogDocSession.RevitVersion, 
				pal.LogAddIn.Name ''
	);

	END 
 ');
 
	PRINT 'PAL - Updating ctcsp_Get_LogElementChanges_ByNamedDateRange'
			
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogElementChanges_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogElementChanges_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogElementChanges_ByNamedDateRange]
	(
		@p_NamedDateRange nvarchar(7)
    )
	AS
	BEGIN
	-- SET NOCOUNT ON is added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
			
	DECLARE @sql varchar(1000)
	DECLARE @and varchar(1000)

	SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[LogDateTime]'');
	SET @sql = 
			''SELECT        
				pal.LogDocSession.ID, 
				pal.LogDocSession.CentralFileName, 
				pal.LogElement.ElementId,
				pal.LogENUM.Description,
				pal.LogDocSession.UserName,
				pal.LogElement.LogDateTime
			FROM pal.LogDocSession 
				INNER JOIN pal.LogElement ON pal.LogDocSession.ID = pal.LogElement.DocSessionID 
				INNER JOIN pal.LogENUM ON pal.LogElement.ActionType = pal.LogENUM.EnumID
			WHERE   (pal.LogENUM.EnumType = N''''ElementChange'''') ''
			
  
	EXEC(@sql + @and);

	END 
 ');
 
 PRINT ''
	PRINT 'PAL - Updating ctcsp_Get_LogPrintJobs_ByNamedDateRange'
	
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogPrintJobs_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogPrintJobs_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogPrintJobs_ByNamedDateRange]
	(
		@p_NamedDateRange nvarchar(7)
    )
	AS
	BEGIN
	-- SET NOCOUNT ON is added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
			
	DECLARE @sql varchar(1000)
	DECLARE @where varchar(1000)

	SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''[DocDateTime]'');
	SET @sql = 
			''SELECT        
				pal.LogDocSession.ID, 
				pal.LogDocSession.ProjectID,
				pal.LogDocSession.CentralFileName,
				pal.LogDocSession.ShortFileName, 
				pal.LogDocSession.UserName,
				pal.LogPrint.JobID,
				pal.LogPrint.Printed,
				pal.LogPrint.Failed,
				pal.LogPrint.PrintCt,
				pal.LogPrint.FailCt,
				pal.LogPrint.JobStart,
				pal.LogPrint.JobEnd
			FROM pal.LogDocSession 
				INNER JOIN pal.LogPrint ON pal.LogDocSession.ID = pal.LogPrint.DocSessionID ''
  
	EXEC(@sql + @where);

	END ');
	
	PRINT 'PAL - Updating ctcsp_Get_LogWarningSummary_ByNamedDateRange'
	
	begin try
		DROP PROCEDURE [dbo].ctcsp_Get_LogWarningSummary_ByNamedDateRange
	end try
	begin catch
	end catch
	
	begin try
		DROP PROCEDURE [pal].ctcsp_Get_LogWarningSummary_ByNamedDateRange
	end try
	begin catch
	end catch
	
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogWarningSummary_ByNamedDateRange]
	(
		@p_NamedDateRange nvarchar(7)
    )
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)
		Set @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''LogDateTime'');

		SET @sql = 
			''SELECT        
			pal.LogDocSession.ID, 
			pal.LogDocSession.CentralFileName, 
			pal.LogWarningSummary.Description,
			pal.LogWarningSummary.ElementIds,
			pal.LogDocSession.UserName,
			pal.LogWarningSummary.LogDateTime
		FROM pal.LogDocSession 
			INNER JOIN pal.LogWarningSummary ON pal.LogDocSession.ID = pal.LogWarningSummary.DocSessionID ''

		EXEC(@sql + @where + '' ORDER BY LogDateTime'');

	END ');
	PRINT 'End PAL PowerBI stored procedures'	
	PRINT ''
	PRINT 'Snapshot - Modify stored procs to work with int IDs'
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_ReadWithUnassignedProjectIds'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadWithUnassignedProjectIds' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithUnassignedProjectIds]
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithUnassignedProjectIds] 
		(
			@p_CompanyID int
		)	
		AS
		BEGIN
			SET NOCOUNT ON;

		SELECT  
			convert(nvarchar(40), pf.ID) AS ID,       
			pf.CentralOrSingleUserProjectFileName, 
			pf.ShortFileName, 
			0 AS DocProjectID, 
			''None'' AS DocProjectNumber, 
			pp.ProjectID AS ProjProjectID, 
			p1.ProjectNumber AS ProjProjectNumber, 
			pp.AddedDate AS ProjDateTime
		FROM snapshot.ProjectFile As pf
			INNER JOIN
				asset.ProjectPath As pp ON 
				LEFT(pf.CentralOrSingleUserProjectFileName,LEN(pf.CentralOrSingleUserProjectFileName) - charindex(''\'',reverse(pf.CentralOrSingleUserProjectFileName),1)) = pp.CentralFilePath COLLATE SQL_Latin1_General_CP1_CI_AS
				AND pf.ProjectID IS NULL

			INNER JOIN asset.Project AS p1 ON pp.ProjectID = p1.ID 
		WHERE (pf.CompanyID = @p_CompanyID)
		AND   (pf.ProjectID IS NULL)
		ORDER BY CentralOrSingleUserProjectFileName, DocProjectID, ProjDateTime
		END ');

		
		
	PRINT 'Snapshot - Creating ctcsp_ProjectFile_ReadWithUnmatchedProjectIds'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReadWithUnmatchedProjectIds' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithUnmatchedProjectIds]
		EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReadWithUnmatchedProjectIds] 
		(
			@p_CompanyID int
		)	
		AS
		BEGIN
			-- SET NOCOUNT ON is added to prevent extra result sets from
			-- interfering with SELECT statements.
			SET NOCOUNT ON;

			SELECT        
				convert(nvarchar(40), pf.ID) AS ID, 
				pf.CentralOrSingleUserProjectFileName,
				pf.ShortFileName, 
				pf.ProjectID AS DocProjectID, 
				p2.ProjectNumber AS DocProjectNumber, 
				pp.ProjectID AS ProjProjectID, 
				p1.ProjectNumber AS ProjProjectNumber,
				pp.AddedDate AS ProjDateTime
			FROM snapshot.ProjectFile as pf
				INNER JOIN
					asset.ProjectPath pp
					ON LEFT(pf.CentralOrSingleUserProjectFileName,LEN(pf.CentralOrSingleUserProjectFileName) - charindex(''\'',reverse(pf.CentralOrSingleUserProjectFileName),1)) = pp.CentralFilePath COLLATE SQL_Latin1_General_CP1_CI_AS
					AND pf.ProjectID <> pp.ProjectID
				INNER JOIN asset.Project AS p1 ON pp.ProjectID = p1.ID 
				INNER JOIN asset.Project AS p2 ON pf.ProjectID = p2.ID
			WHERE (pf.CompanyID = @p_CompanyID)
			AND   (pf.ProjectID IS NOT NULL)
			ORDER BY CentralOrSingleUserProjectFileName, DocProjectID,ProjDateTime
		END ');
    PRINT ''
	
	PRINT ' '
	PRINT 'SNAPSHOT - Updating ctcsp_ProjectFileSnapshot_Delete'		

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshot_Delete' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFileSnapshot_Delete]
	EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFileSnapshot_Delete]
	(
		@ID uniqueidentifier
	)
	AS
	BEGIN
		SET NOCOUNT OFF;
		-- Deletes an existing ProjectFileSnapshot row
		DELETE FROM [snapshot].[ProjectFileSnapshot] 

		WHERE (([ID] = @ID))
	END ');
	
	
	PRINT ' '
	PRINT 'SNAPSHOT - Updating ctcsp_ProjectFileSnapshot_DeleteWithoutCascade'	
	
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshot_DeleteWithoutCascade' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFileSnapshot_DeleteWithoutCascade]
	EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFileSnapshot_DeleteWithoutCascade]
	(
		@ID uniqueidentifier
	)
	AS
	BEGIN

		DECLARE @ProjectFileID uniqueidentifier

		SET @ProjectFileID = (SELECT ProjectFileID 
		                      FROM snapshot.ProjectFileSnapshot
							  WHERE [ID] = @ID)
		SET NOCOUNT OFF;
		-- Deletes an existing ProjectFileSnapshot row
		DELETE FROM [snapshot].[Workset] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[Warning] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ScheduleField] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[Schedule] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ScheduleField] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ProjectUnusedItem] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ElementParameterValue] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ElementInstance] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ElementDefinition] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ElementType] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[Discipline] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[GroupInstanceParameterValue] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[GroupInstance] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[LinePattern] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ProjectInfoParameter] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ProjectParameterCategory] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ProjectParameterDefinition] WHERE (([ProjectFileSnapshotID] = @ID))

		DELETE FROM [snapshot].[ProjectFileSnapshot] WHERE (([ID] = @ID))

		DELETE FROM [snapshot].[ProjectFile] WHERE (([ID] = @ProjectFileID))
		
	END ');
	
	
	PRINT 'snapshot - Creating ctcsp_Projects_ReadById'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFile_ReplaceProjectId' )
		DROP PROCEDURE [snapshot].[ctcsp_ProjectFile_ReplaceProjectId]
		
	EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFile_ReplaceProjectId] 
		-- This is the list of incoming parameters.  Parameters for the WHERE clause
		-- and updated values must have the same data types as are in the table definition.
			@p_ID uniqueidentifier
			,@p_ProjectId int
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.

		-- Specify in which table the row exists to update
		UPDATE ProjectFile
		
		-- Specify which parameter value goes into which fields
		SET ProjectID = @p_ProjectId
		
			-- Specify how to find which record to update
			WHERE ID = @p_ID

	END ');
	
	PRINT 'ASSET - Creating ctcsp_ProjectPath_ReadProjectID_ByCentralFilePath'
	 IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectPath_ReadProjectID_ByCentralFilePath' )
		DROP PROCEDURE [asset].[ctcsp_ProjectPath_ReadProjectID_ByCentralFilePath]
			EXEC('CREATE PROCEDURE [asset].[ctcsp_ProjectPath_ReadProjectID_ByCentralFilePath]
	(
		@p_CompanyID int,
		@CentralFilePath nvarchar(255)
	)
	AS
	Declare @result int;
		SET NOCOUNT ON;

				
	SET @result = (SELECT  pp.ProjectID
	FROM    asset.ProjectPath AS pp 
	INNER JOIN asset.Project AS p 
	ON pp.ProjectID = p.ID
	WHERE (p.CompanyID = @p_CompanyID)
	AND (pp.CentralFilePath = @CentralFilePath) )

	RETURN @result; ');



	PRINT 'ASSET - Creating ctcsp_Projects_ReadById'
    IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Projects_ReadById' )
		DROP PROCEDURE [asset].[ctcsp_Projects_ReadById]
			EXEC('CREATE PROCEDURE [asset].[ctcsp_Projects_ReadById]
	(
		@ID int
	)
	AS
	BEGIN
		SET NOCOUNT ON;
	
	SELECT ID,
		   Office,
		   ProjectNumber,
		   ProjectName,
		   BuildingName,
		   ClientName,
		   StreetAddress,
   		   StreetAddress2,
		   StreetAddress3,
		   ProjectPhase,
		   ProjectIssueDate,
		   Author,
		   City,
		   StateOrProvince,
		   PostalCode,
		   CountryName,
		   OrgName,
		   OrgDescription,
		   ProjectImage,
		   AddedDate,
		   UpdatedDate,
		   AddedByUserID,
		   UpdatedByUserID
	   
	FROM asset.Project

	WHERE (ID = @ID)
	END ');
	
	
	

	

			PRINT 'Global - Updating stored procedure for asset schema ctcsp_ProjectPath_Create'

			PRINT 'Global - Updating ctcsp_ProjectPath_Create'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectPath_Create' )
				DROP PROCEDURE  asset.ctcsp_ProjectPath_Create
			EXEC('CREATE PROCEDURE [asset].[ctcsp_ProjectPath_Create]
			(
				-- ID is auto generated
				@ProjectID int,
				@AddedByUserID int,
				@DateCreated datetime,
				@CentralFilePath nvarchar(255)
			)
			AS
				SET NOCOUNT OFF;
			
			INSERT INTO [asset].[ProjectPath] (
				[ProjectID],
				[AddedByUserID],
				[AddedDate],
				[CentralFilePath]
			) 
			
			VALUES (
				@ProjectID,
				@AddedByUserID,
				@DateCreated,
				@CentralFilePath
			);
			
			SELECT ID,
				   ProjectID,
				   AddedByUserID,
				   AddedDate,
				   CentralFilePath

			FROM ProjectPath 

			WHERE (ID = SCOPE_IDENTITY()) ')



			PRINT 'Global - Updating stored procedure for asset schema ctcsp_ProjectPath_Update'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectPath_Update' )
				DROP PROCEDURE  asset.ctcsp_ProjectPath_Update
			EXEC('CREATE PROCEDURE [asset].[ctcsp_ProjectPath_Update]
			(
				@ID int,
				@ProjectID int,
				@AddedByUserID int,
				@DateCreated datetime,
				@CentralFilePath nvarchar(255)
			)
			AS
				SET NOCOUNT OFF;

			UPDATE [asset].[ProjectPath] 
			SET [ProjectID] = @ProjectID,
				[AddedByUserID] = @AddedByUserID,
				[AddedDate] = @DateCreated,
				[CentralFilePath] = @CentralFilePath
			WHERE (([ID] = @ID));
			
			SELECT ID,
				   ProjectID,
				   AddedByUserID,
				   AddedDate,
				   CentralFilePath
			FROM asset.ProjectPath 

			WHERE (ID = @ID) ')
			
			


			PRINT 'Global - Updating stored procedure for asset schema ctcsp_ProjectPath_Delete'

			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectPath_Delete' )
				DROP PROCEDURE  asset.ctcsp_ProjectPath_Delete
			EXEC('CREATE PROCEDURE [asset].[ctcsp_ProjectPath_Delete]
			(
				@ID int
			)
			AS
				SET NOCOUNT OFF;
			
			DELETE FROM [asset].[ProjectPath] 
			WHERE (([ID] = @ID)) ')


			PRINT 'Global - Updating stored procedure for asset schema ctcsp_ProjectPath_ReadByAll'
				
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectPath_ReadByAll' )
				DROP PROCEDURE  asset.ctcsp_ProjectPath_ReadByAll
			EXEC('CREATE PROCEDURE [asset].[ctcsp_ProjectPath_ReadByAll]
			(
				@p_CompanyID int
			)
			AS
				SET NOCOUNT ON;
			
			SELECT  pp.ID, 
					pp.ProjectID, 
					pp.AddedByUserID, 
					pp.AddedDate, 
					pp.CentralFilePath
			FROM    asset.ProjectPath AS pp 
			INNER JOIN asset.Project AS p 
			ON pp.ProjectID = p.ID
			WHERE (p.CompanyID = @p_CompanyID) ')
				
				
			PRINT 'Global - Updating stored procedure for asset schema ctcsp_ProjectPath_ReadByCentralFilePath'
				
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectPath_ReadByCentralFilePath' )
					DROP PROCEDURE  asset.ctcsp_ProjectPath_ReadByCentralFilePath
			EXEC('CREATE PROCEDURE [asset].[ctcsp_ProjectPath_ReadByCentralFilePath]
			(
				@p_CompanyID int,
				@CentralFilePath nvarchar(255)
			)
			AS
				SET NOCOUNT ON;
			
			SELECT  pp.ID, 
					pp.ProjectID, 
					pp.AddedDate, 
					pp.CentralFilePath,
					pp.AddedByUserID
			FROM    asset.ProjectPath AS pp 
			INNER JOIN asset.Project AS p 
			ON pp.ProjectID = p.ID
			WHERE (p.CompanyID = @p_CompanyID)
			AND (pp.CentralFilePath = @CentralFilePath) ')	
				

			PRINT 'Global - Updating stored procedure for asset schema ctcsp_ProjectPath_ReadByProjectID'
				
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectPath_ReadByProjectID' )
					DROP PROCEDURE  asset.ctcsp_ProjectPath_ReadByProjectID
			EXEC('CREATE PROCEDURE [asset].[ctcsp_ProjectPath_ReadByProjectID]
			(
				@ProjectID int
			)
			AS
				SET NOCOUNT ON;
			
			SELECT ID,
					ProjectID,
					AddedByUserID,
					AddedDate,
					CentralFilePath

			FROM asset.ProjectPath
			WHERE (ProjectID = @ProjectID) ')
				

			PRINT 'End Asset stored procedures'
			PRINT ' '		
			
	PRINT ' PAL - PowerBI compatibility views '
	
		PRINT ' creating LogDocSessions '
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogDocSessions' )
			DROP VIEW  dbo.LogDocSessions
			EXEC('CREATE VIEW [dbo].[LogDocSessions]
					AS
					SELECT 
						GUID AS Id,
						ISNULL(ProjectID, 0) AS ProjectId, 
						UserName, 
						Server, 
						CentralFileName, 
						ShortFileName, 
						LocalFileName, 
						LocalFileSize, 
						RevitVersion, 
						IsAudit, 
						DocDateTime, 
						LoadTime, 
						STCDuration, 
						STCDateTime, 
						SessionHours, 
						PhaseCt, 
						DesOptCt, 
						WorksetCt, 
						ViewCt, 
						GroupCt, 
						FamilyCt, 
						InstanceCt, 
						UnplacedFamilyCt, 
						InPlaceCt, 
						UnPlacedRoomCt, 
						UnenclosedRoomCt, 
						PlacedRoomCt, 
						UnPlacedSpaceCt, 
						UnenclosedSpaceCt, 
						PlacedSpaceCt, 
						MaterialCt, 
						ViewFilterCt, 
						LevelCt, 
						ElemAddedCt, 
						ElemDeletedCt, 
						ElemModifiedCt, 
						WarningCt, 
						HasClosed
					FROM  pal.LogDocSession
				')
		PRINT ' end creating LogDocSessions '
		PRINT ' creating LogEvents '		
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogEvents' )
			DROP VIEW  dbo.LogEvents
			EXEC('CREATE VIEW [dbo].[LogEvents]
					AS
					SELECT 
						pal.LogEvent.ID AS Id, 
						pal.LogDocSession.GUID AS DocSessionId, 
						pal.LogEvent.EventId, 
						pal.LogEvent.EventType, 
						pal.LogEvent.EventName, 
						pal.LogEvent.ViewName, 
						pal.LogEvent.OpenViewCt, 
						pal.LogEvent.EventDateTime, 
						pal.LogEvent.EventDuration
					FROM pal.LogEvent 
					INNER JOIN pal.LogDocSession ON pal.LogEvent.DocSessionID = pal.LogDocSession.ID
				')
		PRINT ' end creating LogEvents '
		PRINT ' creating LogLinks '		
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogLinks' )
			DROP VIEW  dbo.LogLinks
			EXEC('CREATE VIEW [dbo].[LogLinks]
					AS
					SELECT pal.LogLink.ID AS Id, 
					pal.LogDocSession.GUID AS DocSessionId, 
					pal.LogLink.LinkPath, 
					pal.LogLink.LinkShortFileName, 
					pal.LogLink.LinkType, 
					pal.LogLink.LinkStatus, 
					pal.LogLink.UserName, 
					pal.LogLink.LinksDateTime
					FROM pal.LogLink 
					INNER JOIN pal.LogDocSession ON pal.LogLink.DocSessionID = pal.LogDocSession.ID
				')
		PRINT ' end creating LogLinks '		
		PRINT ' creating LogMachines '		
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogMachines' )
			DROP VIEW  dbo.LogMachines
			EXEC('CREATE VIEW [dbo].[LogMachines]
					AS
					SELECT  pal.LogMachine.ID AS Id, 
							pal.LogDocSession.GUID AS DocSessionId, 
							pal.LogMachine.ProcessorId, 
							pal.LogMachine.MachineName, 
							pal.LogMachine.MAC, 
							pal.LogMachine.OperatingSystem, 
							pal.LogMachine.HDD, 
							pal.LogMachine.Motherboard, 
							pal.LogMachine.Bios, 
							pal.LogMachine.RAM, 
							pal.LogMachine.RAM_Slots, 
							pal.LogMachine.CPU, 
							pal.LogMachine.Video, 
							pal.LogMachine.LogDateTime, 
							pal.LogMachine.IPAddress
					FROM pal.LogMachine 
					INNER JOIN pal.LogDocSession ON pal.LogMachine.DocSessionID = pal.LogDocSession.ID
				')
		PRINT ' end creating LogMachines '	
		PRINT ' creating LogSummaries '		
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogSummaries' )
			DROP VIEW  dbo.LogSummaries
			EXEC('CREATE VIEW [dbo].[LogSummaries]
					AS
					SELECT 	pal.LogSummary.ID AS Id,
							pal.LogDocSession.GUID AS DocSessionId, 
							pal.LogSummary.EventId, 
							pal.LogSummary.GroupCt, 
							pal.LogSummary.InPlaceCt, 
							pal.LogSummary.UnPlacedRoomCt, 
							pal.LogSummary.UnenclosedRoomCt, 
							pal.LogSummary.PlacedRoomCt, 
							pal.LogSummary.UnPlacedSpaceCt, 
							pal.LogSummary.UnenclosedSpaceCt, 
							pal.LogSummary.PlacedSpaceCt, 
							pal.LogSummary.ViewCt, 
							pal.LogSummary.PhaseCt, 
							pal.LogSummary.DesOptCt, 
							pal.LogSummary.LevelCt, 
							pal.LogSummary.UnplacedFamilyCt, 
							pal.LogSummary.SummaryDateTime, 
							pal.LogSummary.ViewFilterCt, 
							pal.LogSummary.MaterialCt, 
							pal.LogSummary.InstanceCt, 
							pal.LogSummary.FamilyCt, 
							pal.LogSummary.WorksetCt
						FROM pal.LogSummary 
						INNER JOIN pal.LogDocSession ON pal.LogSummary.DocSessionID = pal.LogDocSession.ID
				')
		PRINT ' end creating LogSummaries '	
        PRINT ' creating LogViewTypes'
		
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogViewTypes' )
			DROP VIEW  dbo.LogViewTypes
			EXEC('CREATE VIEW [dbo].[LogViewTypes]
					AS
					SELECT pal.LogViewType.ID AS Id, 
						pal.LogDocSession.GUID AS DocSessionId, 
						pal.LogViewType.ViewTypeName, 
						pal.LogViewType.ViewCt, 
						pal.LogViewType.ViewDateTime
					FROM pal.LogViewType 
					INNER JOIN pal.LogDocSession ON pal.LogViewType.DocSessionID = pal.LogDocSession.ID
				')
		
		PRINT ' end creating LogViewTypes'
		PRINT ' creating LogWarnings'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogWarnings' )
			DROP VIEW  dbo.LogWarnings
			EXEC('CREATE VIEW [dbo].[LogWarnings]
					AS
					SELECT pal.LogWarning.ID AS Id, 
							pal.LogDocSession.GUID AS DocSessionId, 
							pal.LogWarning.Severity, 
							pal.LogWarning.WarningId, 
							pal.LogWarning.Description, 
							pal.LogWarning.ElementId, 
							pal.LogWarning.ElementName, 
							pal.LogWarning.LevelName, 
							pal.LogWarning.Workset, 
							pal.LogWarning.WarningDateTime
					FROM pal.LogWarning 
					INNER JOIN pal.LogDocSession ON pal.LogWarning.DocSessionID = pal.LogDocSession.ID
				')
		PRINT ' end creating LogWarnings'
	
	PRINT ' Ending PAL - PowerBI compatibility views '
		

	END  -- PAL upgrades from 3 to 4

	-- By this time all upgrading has been do to version 4, so set those flags.
	IF @palvers < 4
	BEGIN

		PRINT 'End Upgrading PAL AND ASSET schema from version 3 to version 4'
		SET @palvers = 4
	END

	IF @snapvers < 4
	BEGIN
		PRINT 'End Upgrading SNAPSHOT schema from version 3 to version 4'
		SET @snapvers = 4
	END
	
	IF @snapvers = 4
		---------------------------------------------------------------------------------------------------------------------------------------------
		-- MAKE CHANGES TO SNAPSHOT SCHEMA TO UPGRADE FROM VERSION 4 TO VERSION 5
		---------------------------------------------------------------------------------------------------------------------------------------------
		BEGIN

			PRINT ''
			PRINT 'Updating Snapshot items from schema version 4 to version 5'

			IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'ElementTypeConstructionLayer')
				BEGIN
				-- CREATE THE NEW ElementTypeConstructionLayer TABLE.

				PRINT 'Snapshot - Creating the ElementTypeConstructionLayer table'
											
				CREATE TABLE [snapshot].[ElementTypeConstructionLayer](
					[ID] [uniqueidentifier] NOT NULL,
					[ElementTypeID] [uniqueidentifier] NOT NULL,
					[ElementTypeName] [nvarchar](MAX) NOT NULL,
					[ProjectFileSnapshotID] [uniqueidentifier] NOT NULL,
					[LayerIndex] [int] NOT NULL,
					[IsCoreLayer] [bit] NOT NULL,
					[FunctionName] [nvarchar](50) NOT NULL,
					[MaterialName] [nvarchar](255) NOT NULL,
					[ThicknessValueInSystemUnits] [float] NOT NULL,
					[ThicknessValueInDisplayUnits] [float] NOT NULL,
					[ThicknessValueAsString] [nvarchar](40) NOT NULL,
					[ThicknessDisplayUnitsSymbol] [nvarchar](20) NOT NULL,
					[Wraps] [bit] NOT NULL,
					[StructuralMaterial] [bit] NOT NULL,
					[Variable] [bit] NULL,
					[DeckEmbeddingTypeName] [nvarchar](40) NULL,
					[DeckProfileElementID] [int] NULL,
					[DeckProfileName] [nvarchar](255) NULL,
				 CONSTRAINT [PK_ElementTypeConstructionLayer] PRIMARY KEY CLUSTERED 
				(
					[ID] ASC
				)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
				) ON [PRIMARY]

				ALTER TABLE [snapshot].[ElementTypeConstructionLayer]  WITH CHECK ADD  CONSTRAINT [FK_ElementTypeConstructionLayer_ElementType] FOREIGN KEY([ElementTypeID])
				REFERENCES [snapshot].[ElementType] ([ID])
				ON UPDATE CASCADE
				ON DELETE CASCADE
			
				ALTER TABLE [snapshot].[ElementTypeConstructionLayer] CHECK CONSTRAINT [FK_ElementTypeConstructionLayer_ElementType]
			END


			PRINT 'Snapshot - Creating the ctcsp_ElementTypeConstructionLayer_ReadByElementTypeID stored procedure'
			
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementTypeConstructionLayer_ReadByElementTypeID')
				DROP PROCEDURE [snapshot].ctcsp_ElementTypeConstructionLayer_ReadByElementTypeID
			

			-- Reads all the element type layer rows within a snapshot for a given element (family) type definition
			EXEC('
			CREATE PROCEDURE [snapshot].[ctcsp_ElementTypeConstructionLayer_ReadByElementTypeID]
			(
				@ElementTypeID uniqueidentifier
			)
			AS
				SET NOCOUNT ON;
				
			SELECT ID,
				   ElementTypeID,
				   ElementTypeName,
				   ProjectFileSnapshotID,
				   LayerIndex,
				   IsCoreLayer,
				   FunctionName,
				   MaterialName,
				   ThicknessValueInSystemUnits,
				   ThicknessValueInDisplayUnits,
				   ThicknessValueAsString,
				   ThicknessDisplayUnitsSymbol,
				   Wraps,
				   StructuralMaterial,
				   Variable,
				   DeckEmbeddingTypeName,
				   DeckProfileElementID,
				   DeckProfileName
				   
			FROM snapshot.ElementTypeConstructionLayer

			WHERE  ElementTypeID = @ElementTypeID
			ORDER BY LayerIndex

			')

			
			IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'ElementInstanceDimensionSegment')
				BEGIN
				PRINT 'Snapshot - Creating the ElementInstanceDimensionSegment table'


				/****** Object:  Table [snapshot].[ElementInstanceDimensionSegment]    Script Date: 8/20/2019 1:41:38 PM ******/

				CREATE TABLE [snapshot].[ElementInstanceDimensionSegment](
					[ID] [uniqueidentifier] NOT NULL,
					[ElementInstanceID] [uniqueidentifier] NOT NULL,
					[ProjectFileSnapshotID] [uniqueidentifier] NOT NULL,
					[SegmentIndex] [int] NOT NULL,
					[UsesOverrideValue] [bit] NOT NULL,
					[ValueInSystemUnits] [float] NOT NULL,
					[ValueInDisplayUnits] [float] NOT NULL,
					[ValueAsString] [nvarchar](40) NOT NULL,
					[DisplayUnitSymbol] [nvarchar](20) NOT NULL,
					[ValueOverride] [nvarchar](255) NULL,
					[AboveText] [nvarchar](255) NULL,
					[BelowText] [nvarchar](255) NULL,
					[PrefixText] [nvarchar](255) NULL,
					[SuffixText] [nvarchar](255) NULL,
				 CONSTRAINT [PK_snapshot.ElementInstanceDimensionSegment] PRIMARY KEY CLUSTERED 
				(
					[ID] ASC
				)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
				) ON [PRIMARY]


				ALTER TABLE [snapshot].[ElementInstanceDimensionSegment]  WITH CHECK ADD  CONSTRAINT [FK_ElementInstanceDimensionSegment_ElementInstance] FOREIGN KEY([ElementInstanceID])
				REFERENCES [snapshot].[ElementInstance] ([ID])
				ON UPDATE CASCADE
				ON DELETE CASCADE

				ALTER TABLE [snapshot].[ElementInstanceDimensionSegment] CHECK CONSTRAINT [FK_ElementInstanceDimensionSegment_ElementInstance]
			END
			
			
			
			
			PRINT 'Snapshot - Creating the ctcsp_ElementInstanceDimensionSegment_ReadByElementInstanceID stored procedure'
										
			
			IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ElementInstanceDimensionSegment_ReadByElementInstanceID')
				DROP PROCEDURE [snapshot].ctcsp_ElementInstanceDimensionSegment_ReadByElementInstanceID
			

			-- Reads all the element (family) instance dimension segment rows within a snapshot for a given element (family = dimension) instance
			EXEC('
			CREATE PROCEDURE [snapshot].[ctcsp_ElementInstanceDimensionSegment_ReadByElementInstanceID]
			(
				@ElementInstanceID uniqueidentifier
				,@OnlyGetOverriddenSegments bit = 0
			)
			AS
				SET NOCOUNT ON;
				
			SELECT ID,
				   ElementInstanceID,
				   ProjectFileSnapshotID,
				   SegmentIndex,
				   UsesOverrideValue,
				   ValueInSystemUnits,
				   ValueInDisplayUnits,
				   ValueAsString,
				   DisplayUnitSymbol,
				   ValueOverride,
				   AboveText,
				   BelowText,
				   PrefixText,
				   SuffixText
				   
			FROM snapshot.ElementInstanceDimensionSegment

			WHERE  ElementInstanceID = @ElementInstanceID AND (@OnlyGetOverriddenSegments = 0 OR UsesOverrideValue = 1)
			ORDER BY SegmentIndex

			')	

			PRINT 'Snapshot - Adding dimension summary fields to the ProjectFileSnapshot table'
			
			IF NOT EXISTS(SELECT * FROM   INFORMATION_SCHEMA.COLUMNS 
				 WHERE  TABLE_NAME = 'ProjectFileSnapshot'
                 AND COLUMN_NAME = 'DimensionSegmentInstanceCount') 
				ALTER TABLE [snapshot].ProjectFileSnapshot Add DimensionSegmentInstanceCount int null 

			IF  NOT EXISTS(SELECT * FROM   INFORMATION_SCHEMA.COLUMNS 
				WHERE  TABLE_NAME = 'ProjectFileSnapshot'
                AND COLUMN_NAME = 'DimensionSegmentInstanceOverrideCount') 
			ALTER TABLE [snapshot].ProjectFileSnapshot Add DimensionSegmentInstanceOverrideCount int null
			
			IF NOT EXISTS(SELECT * FROM   INFORMATION_SCHEMA.COLUMNS 
				WHERE  TABLE_NAME = 'ProjectFileSnapshot'
                AND COLUMN_NAME = 'DimensionSegmentsInstanceHealthScore') 
			ALTER TABLE [snapshot].ProjectFileSnapshot Add DimensionSegmentsInstanceHealthScore float null 

			
			PRINT 'Snapshot - Updating ctcsp_ProjectFileSnapshot_ReadByProjectFileID'
				IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_ProjectFileSnapshot_ReadByProjectFileID' )
				DROP PROCEDURE [snapshot].[ctcsp_ProjectFileSnapshot_ReadByProjectFileID]
				EXEC('CREATE PROCEDURE [snapshot].[ctcsp_ProjectFileSnapshot_ReadByProjectFileID]
				(
					@ProjectFileID uniqueidentifier
				)
				AS
					SET NOCOUNT ON;
				
				SELECT	ID, 
						CompanyID,
						ProjectFileID, 
						SnapshotName,
						SnapshotDateAndTime, 
						SnapshotDateOnly,
						SnapshotTimeOnly,
						RecordedByUserName,
						FullFileName, 
						CentralOrSingleUserProjectFilePath,
						CentralOrSingleUserProjectShortFileName,
						FileSizeInBytes, 
						FileSizeInMegabytes,
						LastSaveTime, 
						LastSavedWithRevitVersion, 
						RecordedWithRevitVersion, 
						RecordedInRevitLanguageID, 
						RecordedInRevitLanguageName, 
						LastSavedWithRevitBuild, 
						RecordedWithRevitBuild, 
						SnapshotSettings, 
						SchemaVersionDuringSnapshot,
						SnapshotDurationInSeconds,
						ProcessingSeconds,
						LengthDisplayUnitType,
						ProjectAddress,
						ProjectStatus,
						ActiveViewName,
						StartingViewName,
						StandardViewsCount,
						SheetsCount,
						StandardViewsOnSheetsCount,
						StandardViewsNotOnSheetsCount,
						StandardViewsHealthScore,
						ViewTemplatesCount,
						ViewTemplatesUnusedCount,
						ViewTemplatesHealthScore,
						ViewFiltersCount,
						ViewFiltersUnusedCount,
						ViewFiltersHealthScore,
						ComponentFamiliesLoadedCount,
						ComponentFamiliesUnusedCount,
						ComponentFamilyTypesCount,
						ComponentFamilyTypesUnusedCount,
						ComponentFamilyInstanceCount,
						ComponentFamilyHealthScore,
						ComponentFamilyTypesHealthScore,
						ModelSystemFamilyTypesCount,
						ModelSystemFamilyTypesUnusedCount,
						ModelSystemFamilyInstanceCount,
						ModelSystemFamilyHealthScore,
						ViewportSystemFamilyTypesCount,
						ViewportSystemFamilyTypesUnusedCount,
						ViewportSystemFamilyTypesHealthScore,
						ColorFillLegendSystemFamilyTypesCount,
						ColorFillLegendSystemFamilyTypesUnusedCount,
						ColorFillLegendSystemFamilyTypesHealthScore,
						ColorFillSchemeSystemFamilyTypesCount,
						ColorFillSchemeSystemFamilyTypesUnusedCount,
						ColorFillSchemeSystemFamilyTypesHealthScore,
						TextSystemFamilyTypesCount,
						TextSystemFamilyTypesUnusedCount,
						TextSystemFamilyInstanceCount,
						TextSystemFamilyTypesHealthScore,
						DimensionSystemFamilyTypesCount,
						DimensionSystemFamilyTypesUnusedCount,
						DimensionSystemFamilyInstanceCount,
						DimensionSystemFamilyTypesHealthScore,
						MaterialTypesCount,
						MaterialTypesUnusedCount,
						MaterialTypesHealthScore,
						LineInstanceCount,
						LineStylesCount,
						LineStylesUnusedCount,
						LineStylesHealthScore,
						LinePatternsCount,
						LinePatternsUnusedCount,
						LinePatternsHealthScore,
						RevisionsCount,
						RevisionsUnusedCount,
						RevisionsHealthScore,
						ElementDefinitionCount,
						ElementInstanceCount,
						GroupTypesCount,
						GroupInstanceCount,
						WarningsCount,
						WarningsHealthScore,
						ScheduleCount,
						ProjectParameterCount,
						InvisibleProjectParameterCount,
						ProjectParameterHealthScore,
						UserWorksetCount,
						ImportsCount,
						LinksCount,
						SnapshotDateAndTimeUTC,
						DimensionSegmentInstanceCount,
						DimensionSegmentInstanceOverrideCount,
						DimensionSegmentsInstanceHealthScore
					
				FROM ProjectFileSnapshot 

				Where ProjectFileID = @ProjectFileID ');			
			

				-- Add some performance enhancements
				IF NOT EXISTS (
					SELECT 'foo'
					FROM sys.indexes 
					WHERE object_id = OBJECT_ID('[pal].[LogElement]')
					AND name='IX_LogDocElement_DocSessionID')

					CREATE NONCLUSTERED INDEX IX_LogDocElement_DocSessionID ON [pal].[LogElement] (DocSessionID)

				IF NOT EXISTS (
					SELECT 'foo'
					FROM sys.indexes 
					WHERE object_id = OBJECT_ID('[pal].[LogWarning]')
					AND name='IX_LogWarning_DocSessionID')
					CREATE NONCLUSTERED INDEX IX_LogWarning_DocSessionID ON [pal].[LogWarning] (DocSessionID)
	
	
		END   -- Upgrading Snapshot schema from version 4 to version 5
		
	-- By this time all upgrading has been do to version 5, so set those flags.
	SET @snapvers = 5
	
    -- Finally store the latest schema version into the database.	

	-- Update Schema Version to the latest version
	UPDATE  [asset].SchemaData
	SET     [CurrentActivitySchemaVersion] = @palvers,
			[CurrentSnapshotSchemaVersion] = @snapvers

	IF @palvers = 4 
	BEGIN

	DECLARE	@return_value int
	DECLARE @newPKFieldNamesCommaDelimited NVARCHAR(100)
	DECLARE @newPKConstraintNameOverride NVARCHAR(100)
	DECLARE @parentAlreadyLinkedFieldName NVARCHAR(100)
	DECLARE @parentExistingFieldToLinkTo NVARCHAR(100)
	DECLARE @tableName NVARCHAR(100)
	DECLARE @primaryKeyConstraintName NVARCHAR(100)


	--DECLARE @CompanyGUIDValue NVARCHAR(36) 
	DECLARE @ConstraintValue NVARCHAR(100)
	DECLARE @ConstraintName NVARCHAR(100)
	DECLARE	@ResultText nvarchar(2048)
	DECLARE @ReturnValue int
	DECLARE @ResultValue int

	DECLARE @childAlreadyLinkedFieldName NVARCHAR(100)
	DECLARE @childFieldNameToAdd NVARCHAR(100)
	DECLARE @relationNameToDelete NVARCHAR(100)
	DECLARE @relationToCreateNameOverride NVARCHAR(100)
	DECLARE @IndexName nvarchar(2048)
	DECLARE @tableNameNoSchema NVARCHAR(255)
	
	DELETE
	FROM [pal].[LogMachine]
	WHERE ID NOT IN
	(
	SELECT MAX(ID)
	FROM [pal].[LogMachine]
	GROUP BY DocSessionID)

	IF @showLogMessages = 1
		PRINT 'Stored Procedure:  Creating ctcsp___1_DropChildConstraint'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp___1_DropChildConstraint' )
		DROP PROCEDURE  dbo.ctcsp___1_DropChildConstraint
	EXEC('CREATE PROCEDURE [dbo].[ctcsp___1_DropChildConstraint]
	(
		@showLogMessages bit,
		@tableName nvarchar(2048),
        @primaryKeyConstraintName nvarchar(2048)
	)

	AS
		SET NOCOUNT ON;

		IF @showLogMessages = 1
			BEGIN
				PRINT ''     BEGIN ctcsp___DropChildConstraint''
				PRINT ''@tableName = '' + @tableName 
				PRINT ''@primaryKeyConstraintName = '' + @primaryKeyConstraintName 
			END

		DECLARE @command nvarchar(2048)
		SET @command = ''ALTER TABLE '' + @tableName + '' DROP CONSTRAINT ['' + @primaryKeyConstraintName + '']''

		EXEC(@command)
	
		IF @showLogMessages = 1
			PRINT ''     END ctcsp___DropChildConstraint'' 
')

IF @showLogMessages = 1
		PRINT 'Stored Procedure:  Creating ctcsp___2_ChangePrimaryKey'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp___2_ChangePrimaryKey' )
		DROP PROCEDURE  dbo.ctcsp___2_ChangePrimaryKey
	EXEC('CREATE PROCEDURE [dbo].[ctcsp___2_ChangePrimaryKey]
	(
		@showLogMessages bit,
		@tableName nvarchar(MAX),
		@tableNameNoSchema NVARCHAR(200),
		@newPKFieldNamesCommaDelimited nvarchar(MAX),
		@createAsClustered bit,
		@newPKConstraintNameOverride NVARCHAR(200) = NULL
	)
	AS
		SET NOCOUNT ON;

		IF @showLogMessages = 1
			BEGIN
				PRINT ''     BEGIN ctcsp__ChangePrimaryKey''
				PRINT ''@tableName = '' + @tableName
				PRINT ''@newPKFieldNamesCommaDelimited = '' + @newPKFieldNamesCommaDelimited
				PRINT ''@newPKConstraintNameOverride = '' + @newPKConstraintNameOverride
			END

		-- Delete the old primary key, if any

		DECLARE @primaryKeyConstraintName nvarchar(MAX) = NULL
		EXEC ctcsp__DeletePrimaryKey 1, @tableName, @tableNameNoSchema, @primaryKeyConstraintName OUTPUT

		DECLARE @command nvarchar(2048)

		IF @primaryKeyConstraintName = NULL
			BEGIN
				IF @showLogMessages = 1
					PRINT ''No existing primary key constraint name was found.  Must create a new name.''
			
				-- Must create the name to use for the new PK
				SET @primaryKeyConstraintName = ''PK_'' + @tableNameNoSchema

				IF @showLogMessages = 1
					PRINT ''Creating new name for primary key: '' + @primaryKeyConstraintName
			END
		ELSE
			BEGIN
				IF @showLogMessages = 1
					PRINT ''Existing primary key constraint name was found: '' + @primaryKeyConstraintName
			END

		IF @newPKConstraintNameOverride IS NOT NULL
		BEGIN
			set @primaryKeyConstraintName = @newPKConstraintNameOverride
		
				IF @showLogMessages = 1
					PRINT ''Using override name for the new primary key constraint: '' + @primaryKeyConstraintName
		END
			
			
		IF @createAsClustered = 1
			BEGIN

				SET @command = ''ALTER TABLE '' + @tableName + '' ADD CONSTRAINT ['' + @primaryKeyConstraintName + ''] PRIMARY KEY CLUSTERED('' + @newPKFieldNamesCommaDelimited + '')''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Creating new CLUSTERED primary key '' + @primaryKeyConstraintName + '' on table '' + @tableName + '' from field(s): '' + @newPKFieldNamesCommaDelimited
						PRINT @command
					END

				EXEC(@command)
			END
		ELSE
			BEGIN

				SET @command = ''ALTER TABLE '' + @tableName + '' ADD CONSTRAINT ['' + @primaryKeyConstraintName + ''] PRIMARY KEY NONCLUSTERED('' + @newPKFieldNamesCommaDelimited + '')''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Creating new NON-CLUSTERED primary key '' + @primaryKeyConstraintName + '' on table '' + @tableName + '' from field(s): '' + @newPKFieldNamesCommaDelimited
						PRINT @command
					END

				EXEC(@command)
			END
	
		IF @showLogMessages = 1
			PRINT ''     END ctcsp__ChangePrimaryKey'' 
')

IF @showLogMessages = 1
		PRINT 'Stored Procedure:  Creating ctcsp___3_AddAndReLinkChildTableGuidForeignKey'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp___3_AddAndReLinkChildTableGuidForeignKey' )
		DROP PROCEDURE  dbo.ctcsp___3_AddAndReLinkChildTableGuidForeignKey
	EXEC('CREATE PROCEDURE [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
	(
		@showLogMessages bit,
		@parentTableName nvarchar(MAX),
		@parentTableNameNoSchema NVARCHAR(200),
		@parentAlreadyLinkedFieldName nvarchar(MAX),
		@parentExistingFieldToLinkTo nvarchar(MAX),
		@childTableName nvarchar(MAX),
		@childTableNameNoSchema NVARCHAR(200),
		@childAlreadyLinkedFieldName nvarchar(MAX),
		@childFieldNameToAdd nvarchar(MAX),
		@deleteOldChildAlreadyLinkedField bit = 1,
		@deleteOldParentAlreadyLinkedField bit = 0,
		@relationNameToDelete nvarchar(200) = NULL,
		@relationToCreateNameOverride nvarchar(200) = NULL,
		@foreignKeyCascadesUpdates bit = 1,
		@foreignKeyCascadesDeletes bit = 1,
		@foreignKeyEnforceForReplication bit = 1,
		@foreignKeyConstraintEnforced bit = 1,
		@autoRenameNewChildFieldToDeletedLinkedChildField bit = 1,
		@childNewFieldToLinkToParentFinalName NVARCHAR(200) = NULL,
		@childNewFieldToLinkToParentAllowsNull bit = 0
	)
	AS
		SET NOCOUNT ON;

		IF @showLogMessages = 1
			BEGIN
				PRINT ''     BEGIN ctcsp__AddChildTableIntFieldLinkToParentTable''
				PRINT ''@parentTableName = '' + @parentTableName
				PRINT ''@parentAlreadyLinkedFieldName = '' + @parentAlreadyLinkedFieldName
				PRINT ''@parentExistingFieldToLinkTo = '' + @parentExistingFieldToLinkTo
				PRINT ''@childTableName = '' + @childTableName
				PRINT ''@childAlreadyLinkedFieldName = '' + @childAlreadyLinkedFieldName
				PRINT ''@childFieldNameToAdd = '' + @childFieldNameToAdd
				PRINT ''@childNewFieldToLinkToParentFinalName = '' + @childNewFieldToLinkToParentFinalName
			END

		DECLARE @command nvarchar(2048)

		SET @command = ''ALTER TABLE '' + @childTableName + '' add '' + @childFieldNameToAdd + '' uniqueidentifier NULL''

		IF @showLogMessages = 1
			BEGIN
				PRINT ''Adding uniqueidentifier field '' + @childFieldNameToAdd + '' to table '' + @childTableName
				PRINT @command
			END

		EXEC(@command)

		SET @command = ''UPDATE '' + @childTableName + 
			 '' SET '' + @childTableName + ''.'' + @childFieldNameToAdd + '' = '' + 
			 @parentTableName + ''.'' + @parentExistingFieldToLinkTo + 
			 '' FROM '' + @childTableName + 
			 '' INNER JOIN '' +
			 @parentTableName + '' ON '' + @parentTableName + ''.'' + @parentAlreadyLinkedFieldName + '' = '' + 
			 @childTableName + ''.'' + @childAlreadyLinkedFieldName

		IF @showLogMessages = 1
			BEGIN
				PRINT ''Re-linking child table '' + @childTableName + '' to parent table '' + @parentTableName + '' using new fields.''
				PRINT @command
			END

		EXEC(@command)

		IF @childNewFieldToLinkToParentAllowsNull = 0
			BEGIN 
				
				SET @command = ''ALTER TABLE '' + @childTableName + '' ALTER COLUMN '' + @childFieldNameToAdd + '' uniqueidentifier NOT NULL''
				
				IF @showLogMessages = 1
					BEGIN
						PRINT ''Making new child table ('' + @childTableName + '') field ('' + @childFieldNameToAdd + '') not nullable.''
						PRINT @command
					END

				EXEC(@command)
			END

		IF @relationNameToDelete IS NOT NULL
			BEGIN
				IF @showLogMessages = 1
					PRINT ''Finding existing relationship '' + @relationNameToDelete 
				
				DECLARE @foriegnKeyConstraintNameFound nvarchar(MAX)
				SELECT @foriegnKeyConstraintNameFound = name 
					FROM sys.foreign_keys  
					WHERE OBJECT_NAME(parent_object_id) = @childTableNameNoSchema AND name = @relationNameToDelete;  

				if @foriegnKeyConstraintNameFound IS NOT NULL
					BEGIN
						SET @command = ''ALTER TABLE '' + @childTableName + '' DROP CONSTRAINT ['' + @foriegnKeyConstraintNameFound + '']''

						IF @showLogMessages = 1
							BEGIN
								PRINT ''Existing relationship found.  Deleting it:  '' + @foriegnKeyConstraintNameFound 
								PRINT @command
							END

						EXEC(@command)
					END
				ELSE
					BEGIN
						if @showLogMessages = 1
								PRINT ''The relationship WAS NOT found:  '' + @relationNameToDelete 
					END
			END

		DECLARE @newRelationshipName nvarchar(200) = ''FK_'' + @childTableName + ''_'' + @parentTableName

		IF @relationToCreateNameOverride IS NOT NULL
			SET @newRelationshipName = @relationToCreateNameOverride

		DECLARE @createFKCommand nvarchar(MAX) = ''ALTER TABLE '' + @childTableName + '' WITH CHECK ADD CONSTRAINT ['' + @newRelationshipName + 
			 ''] FOREIGN KEY ('' + @childFieldNameToAdd + '') REFERENCES '' + @parentTableName + '' ('' + @parentExistingFieldToLinkTo + 
			 '')''

		IF @foreignKeyCascadesUpdates = 1
			SET @createFKCommand += '' ON UPDATE CASCADE''

		IF @foreignKeyCascadesDeletes = 1
			SET @createFKCommand += '' ON DELETE CASCADE''

		IF @foreignKeyEnforceForReplication = 0
			SET @createFKCommand += '' NOT FOR REPLICATION''

		IF @showLogMessages = 1
			BEGIN
				PRINT ''Building the relationship '' + @newRelationshipName + '' between the parent table '' + @parentTableName + '' and child table '' + @childTableName
				PRINT @createFKCommand
			END

		EXEC(@createFKCommand)

		IF @foreignKeyConstraintEnforced = 0
			BEGIN
				DECLARE @updateFKCommand NVARCHAR(200) = ''ALTER TABLE '' + @childTableName + '' NOCHECK CONSTRAINT '' + @newRelationshipName

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Disabling new constraint '' + @newRelationshipName
						PRINT @updateFKCommand
					END

				EXEC(@updateFKCommand)
			END
			 
		IF @deleteOldChildAlreadyLinkedField = 1
			BEGIN
				SET @command = ''ALTER TABLE '' + @childTableName + '' DROP COLUMN '' + @childAlreadyLinkedFieldName

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Deleting the field '' + @childAlreadyLinkedFieldName + '' from child table '' + @childTableName 
						PRINT @command
					END
			
				EXEC(@command)

				IF @autoRenameNewChildFieldToDeletedLinkedChildField = 1
					BEGIN

						SET @command = ''sp_rename '''''' + @childTableName + ''.'' + @childFieldNameToAdd + '''''', '''''' + @childAlreadyLinkedFieldName + '''''', ''''COLUMN''''''

						IF @showLogMessages = 1
							BEGIN
								PRINT ''Renaming the new field '' + @childFieldNameToAdd + '' back to the old linked field name '' + @childAlreadyLinkedFieldName
								PRINT @command
							END

						EXEC(@command)			

					END
					
			END

		IF @childNewFieldToLinkToParentFinalName IS NOT NULL
			BEGIN
			
				SET @command = ''sp_rename '''''' + @childTableName + ''.'' + @childFieldNameToAdd + '''''', '''''' + @childNewFieldToLinkToParentFinalName + '''''', ''''COLUMN''''''

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Renaming the new field '' + @childFieldNameToAdd + '' to the new override name '' + @childNewFieldToLinkToParentFinalName
						PRINT @command
					END

				EXEC(@command)			
			
			END			
			
		IF @deleteOldParentAlreadyLinkedField = 1
			BEGIN
				SET @command = ''ALTER TABLE '' + @parentTableName + '' DROP COLUMN '' + @parentAlreadyLinkedFieldName

				IF @showLogMessages = 1
					BEGIN
						PRINT ''Deleting the field '' + @parentAlreadyLinkedFieldName + '' from parent table '' + @parentTableName 
						PRINT @command
					END
			
				EXEC(@command)
			END

		IF @showLogMessages = 1
			PRINT ''     END ctcsp__AddChildTableIntFieldLinkToParentTable'' ')

IF @showLogMessages = 1
		PRINT 'Stored Procedure:  Creating ctcsp___4_AddGUIDIdentityField'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp___4_AddGUIDIdentityField' )
		DROP PROCEDURE  dbo.ctcsp___4_AddGUIDIdentityField
	EXEC('CREATE PROCEDURE [dbo].[ctcsp___4_AddGUIDIdentityField]
	(
		@showLogMessages bit,
		@tableName nvarchar(MAX),
		@tableNameNoSchema nvarchar(200) = null,
		@newFieldName nvarchar(MAX),
		@makeNewFieldUniqueIndexed bit = 1,
		@makeNewUniqueIndexClustered bit = 0,
		@makeNewFieldSolePrimaryKey bit = 0,
		@makeNewPrimaryKeyNonClustered bit = 0,
		@newPKConstraintNameOverride NVARCHAR(200) = NULL
	)
	AS
		IF @showLogMessages = 1
			BEGIN
				PRINT ''     BEGIN ctcsp__AddGUIDIdentityField''
				PRINT ''@tableName = '' + @tableName
				PRINT ''@newFieldName = '' + @newFieldName
			END

		DECLARE @command nvarchar(2048)

		SET NOCOUNT ON;
		
		
		BEGIN

			if @showLogMessages = 1
				PRINT ''Adding Guid identity field '' + @newFieldName + '' to table '' + @tableName
				
				BEGIN
					SET @command = ''ALTER TABLE '' + @tableName + '' add '' + @newFieldName + '' UniqueIdentifier NOT NULL default newid()''

					IF @showLogMessages = 1
						PRINT @command

					EXEC(@command)

				END

		END
		

		IF @makeNewFieldUniqueIndexed = 1
			BEGIN

				DECLARE @newIndexName NVARCHAR(200) = ''IX_U_'' + @tableNameNoSchema + ''_ID''
				DECLARE @newIndexCommand NVARCHAR(MAX) 

				IF @makeNewUniqueIndexClustered = 0
					BEGIN
						SET @newIndexCommand = ''CREATE UNIQUE INDEX '' + @newIndexName + '' ON '' + @tableName + '' ('' + @newFieldName + '')'' 
					END
				ELSE
					BEGIN
						SET @newIndexCommand = ''CREATE UNIQUE CLUSTERED  INDEX '' + @newIndexName + '' ON '' + @tableName + '' ('' + @newFieldName + '')'' 
					END
			
				if @showLogMessages = 1
					PRINT @newIndexCommand

				EXEC(@newIndexCommand)
			END

		IF @makeNewFieldSolePrimaryKey = 1
			BEGIN
				EXEC dbo.ctcsp__ChangePrimaryKey @showLogMessages, @tableName, @tableNameNoSchema, @newFieldName, @makeNewPrimaryKeyNonClustered, @newPKConstraintNameOverride
			END
	
		IF @showLogMessages = 1
			PRINT ''     END ctcsp__AddGUIDIdentityField'' ')

IF @showLogMessages = 1
		PRINT 'Stored Procedure:  Creating ctcsp___5_GetConstraint'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp___5_GetConstraint' )
		DROP PROCEDURE  dbo.ctcsp___5_GetConstraint
	EXEC('CREATE PROCEDURE [dbo].[ctcsp___5_GetConstraint]
	(
		@TableName nvarchar(2048),
        @ConstraintName nvarchar(2048),
		@ResultText nvarchar(2048) OUTPUT
	)
		AS

		SET NOCOUNT ON;

		BEGIN

		SET @ResultText = (SELECT 
		    --table_view,
			--object_type, 
			constraint_name
			--details
		FROM (
			SELECT schema_name(t.schema_id) + ''.'' + t.[name] as table_view, 
				case when t.[type] = ''U'' then ''Table''
					when t.[type] = ''V'' then ''View''
					end as [object_type],
				case when c.[type] = ''PK'' then ''Primary key''
					when c.[type] = ''UQ'' then ''Unique constraint''
					when i.[type] = 1 then ''Unique clustered index''
					when i.type = 2 then ''Unique index''
					end as constraint_type, 
				isnull(c.[name], i.[name]) as constraint_name,
				substring(column_names, 1, len(column_names)-1) as [details]
			FROM sys.objects t
				LEFT OUTER JOIN sys.indexes i
					on t.object_id = i.object_id
				LEFT OUTER JOIN sys.key_constraints c
					on i.object_id = c.parent_object_id 
					AND i.index_id = c.unique_index_id
			   CROSS APPLY (SELECT col.[name] + '', ''
								FROM sys.index_columns ic
									INNER JOIN sys.columns col
										on ic.object_id = col.object_id
										AND ic.column_id = col.column_id
								WHERE ic.object_id = t.object_id
									AND ic.index_id = i.index_id
										ORDER BY col.column_id
										for xml path ('''') ) D (column_names)
			WHERE is_unique = 1
			
			AND t.is_ms_shipped <> 1
			UNION all 
			SELECT schema_name(fk_tab.schema_id) + ''.'' + fk_tab.name as foreign_table,
				''Table'',
				''Foreign key'',
				fk.name as fk_constraint_name,
				schema_name(pk_tab.schema_id) + ''.'' + pk_tab.name
			FROM sys.foreign_keys fk
				INNER JOIN sys.tables fk_tab
					on fk_tab.object_id = fk.parent_object_id
				INNER JOIN sys.tables pk_tab
					on pk_tab.object_id = fk.referenced_object_id
				INNER JOIN sys.foreign_key_columns fk_cols
					on fk_cols.constraint_object_id = fk.object_id
			UNION all
			SELECT schema_name(t.schema_id) + ''.'' + t.[name],
				''Table'',
				''Check constraint'',
				con.[name] as constraint_name,
				con.[definition]
			FROM sys.check_constraints con
				LEFT OUTER JOIN sys.objects t
					on con.parent_object_id = t.object_id
				LEFT OUTER JOIN sys.all_columns col
					on con.parent_column_id = col.column_id
					AND con.parent_object_id = col.object_id
			UNION all
			SELECT schema_name(t.schema_id) + ''.'' + t.[name],
				''Table'',
				''Default constraint'',
				con.[name],
				col.[name] + '' = '' + con.[definition]
			FROM sys.default_constraints con
				LEFT OUTER JOIN sys.objects t
					on con.parent_object_id = t.object_id
				LEFT OUTER JOIN sys.all_columns col
					on con.parent_column_id = col.column_id
					AND con.parent_object_id = col.object_id) a
		WHERE table_view = @tableName 
		AND constraint_name LIKE @ConstraintName  + ''%'')

		END
 ')

 IF @showLogMessages = 1
		PRINT 'Stored Procedure:  Creating ctcsp___6_GetConstraints'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp___6_GetConstraints' )
		DROP PROCEDURE  dbo.ctcsp___6_GetConstraints
	EXEC('CREATE PROCEDURE [dbo].[ctcsp___6_GetConstraints]
	(
		@TableName nvarchar(2048)
	)
		AS

		SET NOCOUNT ON;

		BEGIN

		SELECT 
		    table_view,
			object_type, 
			constraint_name,
			details
		FROM (
			SELECT schema_name(t.schema_id) + ''.'' + t.[name] as table_view, 
				case when t.[type] = ''U'' then ''Table''
					when t.[type] = ''V'' then ''View''
					end as [object_type],
				case when c.[type] = ''PK'' then ''Primary key''
					when c.[type] = ''UQ'' then ''Unique constraint''
					when i.[type] = 1 then ''Unique clustered index''
					when i.[type] = 2 then ''Unique index''
					end as constraint_type, 
				isnull(c.[name], i.[name]) as constraint_name,
				substring(column_names, 1, len(column_names)-1) as [details]
			FROM sys.objects t
				LEFT OUTER JOIN sys.indexes i
					on t.object_id = i.object_id
				LEFT OUTER JOIN sys.key_constraints c
					on i.object_id = c.parent_object_id 
					AND i.index_id = c.unique_index_id
			   CROSS APPLY (SELECT col.[name] + '', ''
								FROM sys.index_columns ic
									INNER JOIN sys.columns col
										on ic.object_id = col.object_id
										AND ic.column_id = col.column_id
								WHERE ic.object_id = t.object_id
									AND ic.index_id = i.index_id
										ORDER BY col.column_id
										for xml path ('''') ) D (column_names)
			WHERE is_unique = 1
			
			AND t.is_ms_shipped <> 1
			UNION all 
			SELECT schema_name(fk_tab.schema_id) + ''.'' + fk_tab.name as foreign_table,
				''Table'',
				''Foreign key'',
				fk.name as fk_constraint_name,
				schema_name(pk_tab.schema_id) + ''.'' + pk_tab.name
			FROM sys.foreign_keys fk
				INNER JOIN sys.tables fk_tab
					on fk_tab.object_id = fk.parent_object_id
				INNER JOIN sys.tables pk_tab
					on pk_tab.object_id = fk.referenced_object_id
				INNER JOIN sys.foreign_key_columns fk_cols
					on fk_cols.constraint_object_id = fk.object_id
			UNION all
			SELECT schema_name(t.schema_id) + ''.'' + t.[name],
				''Table'',
				''Check constraint'',
				con.[name] as constraint_name,
				con.[definition]
			FROM sys.check_constraints con
				LEFT OUTER JOIN sys.objects t
					on con.parent_object_id = t.object_id
				LEFT OUTER JOIN sys.all_columns col
					on con.parent_column_id = col.column_id
					AND con.parent_object_id = col.object_id
			UNION all
			SELECT schema_name(t.schema_id) + ''.'' + t.[name],
				''Table'',
				''Default constraint'',
				con.[name],
				col.[name] + '' = '' + con.[definition]
			FROM sys.default_constraints con
				LEFT OUTER JOIN sys.objects t
					on con.parent_object_id = t.object_id
				LEFT OUTER JOIN sys.all_columns col
					on con.parent_column_id = col.column_id
					AND con.parent_object_id = col.object_id) a
		WHERE table_view = @tableName 
		Order by table_view
		END ' )

IF @showLogMessages = 1
		PRINT 'Stored Procedure:  Creating ctcsp___7_IndexExists'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp___7_IndexExists' )
		DROP PROCEDURE  dbo.ctcsp___7_IndexExists
	EXEC('CREATE PROCEDURE [dbo].[ctcsp___7_IndexExists]
	(
        @IndexName nvarchar(2048),
		@ResultValue int OUTPUT
	)
		AS
		
		SET NOCOUNT ON;
		DECLARE @result nvarchar(2048)

		BEGIN

		SET @result = ( select i.[name] as index_name
				--substring(column_names, 1, len(column_names)-1) as [columns],
				--case when i.[type] = 1 then ''Clustered index''
				--	when i.[type] = 2 then ''Nonclustered unique index''
				--	when i.[type] = 3 then ''XML index''
				--	when i.[type] = 4 then ''Spatial index''
				--	when i.[type] = 5 then ''Clustered columnstore index''
				--	when i.[type] = 6 then ''Nonclustered columnstore index''
				--	when i.[type] = 7 then ''Nonclustered hash index''
				--	end as index_type,
				--case when i.is_unique = 1 then ''Unique''
				--	else ''Not unique'' end as [unique],
				--schema_name(t.schema_id) + ''.'' + t.[name] as table_view, 
				--case when t.[type] = ''U'' then ''Table''
				--	when t.[type] = ''V'' then ''View''
				--	end as [object_type]
			from sys.objects t
				inner join sys.indexes i
					on t.object_id = i.object_id
				cross apply (select col.[name] + '', ''
								from sys.index_columns ic
									inner join sys.columns col
										on ic.object_id = col.object_id
										and ic.column_id = col.column_id
								where ic.object_id = t.object_id
									and ic.index_id = i.index_id
										order by col.column_id
										for xml path ('''') ) D (column_names)
			where t.is_ms_shipped <> 1
			--and index_id > 0
			and i.[name] = @IndexName )

			IF @result is null
			BEGIN
				SET @ResultValue = 0
			END
			ELSE
			BEGIN
				SET @ResultValue = 1
			END
		END
		RETURN @ResultValue ' )

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
	PRINT 'Table:  Drop Constraint FK_LogAddIn_LogDocSession'

EXEC	
	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
	@showLogMessages = 1,
	@tableName = N'pal.LogAddIn',
	@primaryKeyConstraintName = N'FK_LogAddIn_LogDocSession'

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_LogCrash_LogDocSession'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogCrash',
		@primaryKeyConstraintName = N'FK_LogCrash_LogDocSession'

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_LogElement_LogDocSession'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogElement',
		@primaryKeyConstraintName = N'FK_LogElement_LogDocSession'

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_LogEvent_LogDocSession'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogEvent',
		@primaryKeyConstraintName = N'FK_LogEvent_LogDocSession'

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_LogLink_LogDocSession'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogLink',
		@primaryKeyConstraintName = N'FK_LogLink_LogDocSession'

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_LogMachine_LogDocSession'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogMachine',
		@primaryKeyConstraintName = N'FK_LogMachine_LogDocSession'

PRINT '  ' + CHAR(10) + ' '
		
IF @showLogMessages = 1
	PRINT 'Table:  Drop Constraint FK_pal.LogPrint_pal.LogDocument_DocSessionID'
	SET @TableName = 'pal.LogPrint'
	SET @ConstraintName = 'FK'
	EXEC	@ReturnValue  = [dbo].[ctcsp___5_GetConstraint]
			@TableName,
			@ConstraintName,
			@ResultText OUTPUT
	
	IF ( @ResultText is not null )
	BEGIN
		SET @command = 'ALTER Table ' + @TableName + ' DROP CONSTRAINT [' +  @ResultText + ']'
		EXEC (@command);
	END

PRINT '  ' + CHAR(10) + ' '
		
IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_LogSummary_LogDocSession'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogSummary',
		@primaryKeyConstraintName = N'FK_LogSummary_LogDocSession'


PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_LogViewType_LogDocSession'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogViewType',
		@primaryKeyConstraintName = N'FK_LogViewType_LogDocSession'

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_LogWarning_LogDocSession'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogWarning',
		@primaryKeyConstraintName = N'FK_LogWarning_LogDocSession'

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_pal.LogWarningSummary_pal.LogDocument_DocSessionID'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogWarningSummary',
		@primaryKeyConstraintName = N'FK_pal.LogWarningSummary_pal.LogDocument_DocSessionID'

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'Table:  Drop Constraint FK_LogDocumentProjChange_LogDocSession'

	EXEC	@return_value = [dbo].[ctcsp___1_DropChildConstraint]
		@showLogMessages = 1,
		@tableName = N'pal.LogDocumentProjChange',
		@primaryKeyConstraintName = N'FK_LogDocumentProjChange_LogDocSession'

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1 PRINT 'TABLE:  Change primary key to GUID: pal.LogDocSession'
	SET @parentTableName = 'pal.LogDocSession'
	SET @parentTableNameNoSchema = 'LogDocSession'
	SET @newPKFieldNamesCommaDelimited = 'GUID'
	SET @newPKConstraintNameOverride = 'PK_LogDocSession'

	EXEC @return_value = [dbo].[ctcsp___2_ChangePrimaryKey]
		@showLogMessages = 1,
		@tableName = @parentTableName,
		@tableNameNoSchema = @parentTableNameNoSchema,
		@newPKFieldNamesCommaDelimited = @newPKFieldNamesCommaDelimited,
		@createAsClustered = 1,
		@newPKConstraintNameOverride = @newPKConstraintNameOverride

	

	SET @parentAlreadyLinkedFieldName = 'ID'
	SET @parentExistingFieldToLinkTo = 'GUID'
	SET @childTableName = 'pal.LogAddIn'
	SET @childTableNameNoSchema = 'LogAddIn'
	SET @childAlreadyLinkedFieldName = 'DocSessionID'
	SET @childFieldNameToAdd = 'DocSessionGUID'
	SET @relationNameToDelete = 'FK_LogAddIn_LogDocSession'
	SET @relationToCreateNameOverride = 'FK_LogAddIn_LogDocSession'
	SET @foreignKeyCascadesUpdates = 1
	SET @foreignKeyCascadesDeletes = 1
	SET @foreignKeyEnforceForReplication = 1
	SET @foreignKeyConstraintEnforced = 1
	SET @autoRenameNewChildFieldToDeletedLinkedChildField = 1
	--SET @autoRenameNewChildFieldToDeletedLinkedChildField = 0
	SET @childNewFieldToLinkToParentAllowsNull = 0

PRINT '  ' + CHAR(10) + ' '

	IF @showLogMessages = 1
		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogAddIn'

	EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
		@showLogMessages = @showLogMessages,
		@parentTableName = @parentTableName,
		@parentTableNameNoSchema = @parentTableNameNoSchema,
		@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
		@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
		@childTableName = @childTableName,
		@childTableNameNoSchema = @childTableNameNoSchema,
		@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
		@childFieldNameToAdd = @childFieldNameToAdd,
		@deleteOldChildAlreadyLinkedField = 1,
		@deleteOldParentAlreadyLinkedField = 0,
		@relationNameToDelete = @relationNameToDelete,
		@relationToCreateNameOverride = @relationToCreateNameOverride,
		@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
		@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
		@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
		@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
		@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
		@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull

PRINT '  ' + CHAR(10) + ' '

	IF @showLogMessages = 1
		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogCrash'

	SET @childTableName = 'pal.LogCrash'
	SET @childTableNameNoSchema = 'LogCrash'
	SET @relationNameToDelete = 'FK_LogCrash_LogDocSession'
	SET @relationToCreateNameOverride = 'FK_LogCrash_LogDocSession'

	EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
		@showLogMessages = @showLogMessages,
		@parentTableName = @parentTableName,
		@parentTableNameNoSchema = @parentTableNameNoSchema,
		@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
		@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
		@childTableName = @childTableName,
		@childTableNameNoSchema = @childTableNameNoSchema,
		@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
		@childFieldNameToAdd = @childFieldNameToAdd,
		@deleteOldChildAlreadyLinkedField = 1,
		@deleteOldParentAlreadyLinkedField = 0,
		@relationNameToDelete = @relationNameToDelete,
		@relationToCreateNameOverride = @relationToCreateNameOverride,
		@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
		@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
		@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
		@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
		@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
		@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull

PRINT '  ' + CHAR(10) + ' '

	IF @showLogMessages = 1
		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogDocumentProjChange'

	SET @childTableName = 'pal.LogDocumentProjChange'
	SET @childTableNameNoSchema = 'LogDocumentProjChange'
	SET @relationNameToDelete = 'FK_LogDocumentProjChange_LogDocSession'
	SET @relationToCreateNameOverride = 'FK_LogDocumentProjChange_LogDocSession'

	EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
		@showLogMessages = @showLogMessages,
		@parentTableName = @parentTableName,
		@parentTableNameNoSchema = @parentTableNameNoSchema,
		@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
		@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
		@childTableName = @childTableName,
		@childTableNameNoSchema = @childTableNameNoSchema,
		@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
		@childFieldNameToAdd = @childFieldNameToAdd,
		@deleteOldChildAlreadyLinkedField = 1,
		@deleteOldParentAlreadyLinkedField = 0,
		@relationNameToDelete = @relationNameToDelete,
		@relationToCreateNameOverride = @relationToCreateNameOverride,
		@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
		@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
		@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
		@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
		@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
		@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
	PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogElement'
	    --DECLARE	@ReturnValue int
		
		SET @IndexName = 'IX_LogDocElement_DocSessionID'

		EXEC	@ReturnValue  = [dbo].[ctcsp___7_IndexExists]
				@IndexName,
				@ResultValue OUTPUT
		
		IF @ResultValue = 1
		BEGIN
			DROP INDEX  
				IX_LogDocElement_DocSessionID ON pal.LogElement 
		END
	    
		SET @childTableName = 'pal.LogElement'
		SET @childTableNameNoSchema = 'LogElement'
		SET @relationNameToDelete = 'FK_LogElement_LogDocSession'
		SET @relationToCreateNameOverride = 'FK_LogElement_LogDocSession'

		EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
			@showLogMessages = @showLogMessages,
			@parentTableName = @parentTableName,
			@parentTableNameNoSchema = @parentTableNameNoSchema,
			@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
			@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
			@childTableName = @childTableName,
			@childTableNameNoSchema = @childTableNameNoSchema,
			@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
			@childFieldNameToAdd = @childFieldNameToAdd,
			@deleteOldChildAlreadyLinkedField = 1,
			@deleteOldParentAlreadyLinkedField = 0,
			@relationNameToDelete = @relationNameToDelete,
			@relationToCreateNameOverride = @relationToCreateNameOverride,
			@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
			@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
			@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
			@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
			@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
			@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull

			CREATE NONCLUSTERED INDEX [IX_LogElement_DocSessionID] ON [pal].[LogElement]
			(
				[DocSessionID] ASC
			)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

PRINT '  ' + CHAR(10) + ' '


	IF @showLogMessages = 1
		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogEvent'

		SET @childTableName = 'pal.LogEvent'
		SET @childTableNameNoSchema = 'LogEvent'
		SET @relationNameToDelete = 'FK_LogEvent_LogDocSession'
		SET @relationToCreateNameOverride = 'FK_LogEvent_LogDocSession'

		EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
			@showLogMessages = @showLogMessages,
			@parentTableName = @parentTableName,
			@parentTableNameNoSchema = @parentTableNameNoSchema,
			@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
			@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
			@childTableName = @childTableName,
			@childTableNameNoSchema = @childTableNameNoSchema,
			@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
			@childFieldNameToAdd = @childFieldNameToAdd,
			@deleteOldChildAlreadyLinkedField = 1,
			@deleteOldParentAlreadyLinkedField = 0,
			@relationNameToDelete = @relationNameToDelete,
			@relationToCreateNameOverride = @relationToCreateNameOverride,
			@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
			@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
			@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
			@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
			@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
			@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull


PRINT '  ' + CHAR(10) + ' '

		IF @showLogMessages = 1
			PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogLink'

		SET @childTableName = 'pal.LogLink'
		SET @childTableNameNoSchema = 'LogLink'
		SET @relationNameToDelete = 'FK_LogLink_LogDocSession'
		SET @relationToCreateNameOverride = 'FK_LogLink_LogDocSession'

		EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
			@showLogMessages = @showLogMessages,
			@parentTableName = @parentTableName,
			@parentTableNameNoSchema = @parentTableNameNoSchema,
			@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
			@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
			@childTableName = @childTableName,
			@childTableNameNoSchema = @childTableNameNoSchema,
			@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
			@childFieldNameToAdd = @childFieldNameToAdd,
			@deleteOldChildAlreadyLinkedField = 1,
			@deleteOldParentAlreadyLinkedField = 0,
			@relationNameToDelete = @relationNameToDelete,
			@relationToCreateNameOverride = @relationToCreateNameOverride,
			@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
			@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
			@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
			@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
			@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
			@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull


PRINT '  ' + CHAR(10) + ' '

	IF @showLogMessages = 1
		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogMachine'

		SET @IndexName = 'UNQ_LogMachine_LogDocSession'

		EXEC	@ReturnValue  = [dbo].[ctcsp___7_IndexExists]
				@IndexName,
				@ResultValue OUTPUT
		
		IF @ResultValue = 1
		BEGIN
			--DROP INDEX  UNQ_LogMachine_LogDocSession ON pal.LogMachine 
			ALTER TABLE [pal].[LogMachine] DROP constraint  UNQ_LogMachine_LogDocSession
		END

		SET @childTableName = 'pal.LogMachine'
		SET @childTableNameNoSchema = 'LogMachine'
		SET @relationNameToDelete = 'FK_LogMachine_LogDocSession'
		SET @relationToCreateNameOverride = 'FK_LogMachine_LogDocSession'

		EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
			@showLogMessages = @showLogMessages,
			@parentTableName = @parentTableName,
			@parentTableNameNoSchema = @parentTableNameNoSchema,
			@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
			@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
			@childTableName = @childTableName,
			@childTableNameNoSchema = @childTableNameNoSchema,
			@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
			@childFieldNameToAdd = @childFieldNameToAdd,
			@deleteOldChildAlreadyLinkedField = 1,
			@deleteOldParentAlreadyLinkedField = 0,
			@relationNameToDelete = @relationNameToDelete,
			@relationToCreateNameOverride = @relationToCreateNameOverride,
			@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
			@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
			@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
			@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
			@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
			@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull

			-- do this once DocSessionGUID is renamed to DocSessionID
		--ALTER TABLE [pal].[LogMachine] ADD  CONSTRAINT [UNQ_LogMachine_LogDocSession1] UNIQUE NONCLUSTERED 
		--(
		--	[DocSessionID] ASC
		--)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

PRINT '  ' + CHAR(10) + ' '

	IF @showLogMessages = 1
		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogSummary'

		SET @childTableName = 'pal.LogSummary'
		SET @childTableNameNoSchema = 'LogSummary'
		SET @relationNameToDelete = 'FK_LogSummary_LogDocSession'
		SET @relationToCreateNameOverride = 'FK_LogSummary_LogDocSession'

		EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
			@showLogMessages = @showLogMessages,
			@parentTableName = @parentTableName,
			@parentTableNameNoSchema = @parentTableNameNoSchema,
			@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
			@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
			@childTableName = @childTableName,
			@childTableNameNoSchema = @childTableNameNoSchema,
			@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
			@childFieldNameToAdd = @childFieldNameToAdd,
			@deleteOldChildAlreadyLinkedField = 1,
			@deleteOldParentAlreadyLinkedField = 0,
			@relationNameToDelete = @relationNameToDelete,
			@relationToCreateNameOverride = @relationToCreateNameOverride,
			@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
			@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
			@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
			@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
			@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
			@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull


PRINT '  ' + CHAR(10) + ' '

	IF @showLogMessages = 1
		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogPrint'

	SET @childTableName = 'pal.LogPrint'
	SET @childTableNameNoSchema = 'LogPrint'
	SET @relationNameToDelete = 'FK_LogPrint_LogDocSession'
	SET @relationToCreateNameOverride = 'FK_LogPrint_LogDocSession'

	EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
		@showLogMessages = @showLogMessages,
		@parentTableName = @parentTableName,
		@parentTableNameNoSchema = @parentTableNameNoSchema,
		@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
		@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
		@childTableName = @childTableName,
		@childTableNameNoSchema = @childTableNameNoSchema,
		@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
		@childFieldNameToAdd = @childFieldNameToAdd,
		@deleteOldChildAlreadyLinkedField = 1,
		@deleteOldParentAlreadyLinkedField = 0,
		@relationNameToDelete = @relationNameToDelete,
		@relationToCreateNameOverride = @relationToCreateNameOverride,
		@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
		@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
		@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
		@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
		@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
		@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull

PRINT '  ' + CHAR(10) + ' '

	IF @showLogMessages = 1

		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogWarning'

		SET @IndexName = 'IX_LogWarning_DocSessionID'

		EXEC	@ReturnValue  = [dbo].[ctcsp___7_IndexExists]
				@IndexName,
				@ResultValue OUTPUT
		
		IF @ResultValue = 1
		BEGIN
			DROP INDEX  
				IX_LogWarning_DocSessionID ON pal.LogWarning
		END


		SET @childTableName = 'pal.LogWarning'
		SET @childTableNameNoSchema = 'LogWarning'
		SET @relationNameToDelete = 'FK_LogWarning_LogDocSession'
		SET @relationToCreateNameOverride = 'FK_LogWarning_LogDocSession'

		EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
			@showLogMessages = @showLogMessages,
			@parentTableName = @parentTableName,
			@parentTableNameNoSchema = @parentTableNameNoSchema,
			@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
			@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
			@childTableName = @childTableName,
			@childTableNameNoSchema = @childTableNameNoSchema,
			@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
			@childFieldNameToAdd = @childFieldNameToAdd,
			@deleteOldChildAlreadyLinkedField = 1,
			@deleteOldParentAlreadyLinkedField = 0,
			@relationNameToDelete = @relationNameToDelete,
			@relationToCreateNameOverride = @relationToCreateNameOverride,
			@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
			@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
			@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
			@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
			@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
			@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull

		CREATE NONCLUSTERED INDEX [IX_LogWarning_DocSessionID] ON [pal].[LogWarning]
		(
			[DocSessionID] ASC
		)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

PRINT '  ' + CHAR(10) + ' '
	

	IF @showLogMessages = 1
		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID) to LogViewType'

	SET @childTableName = 'pal.LogViewType'
	SET @childTableNameNoSchema = 'LogViewType'
	SET @relationNameToDelete = 'FK_LogViewType_LogDocSession'
	SET @relationToCreateNameOverride = 'FK_LogViewType_LogDocSession'

	EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
		@showLogMessages = @showLogMessages,
		@parentTableName = @parentTableName,
		@parentTableNameNoSchema = @parentTableNameNoSchema,
		@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
		@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
		@childTableName = @childTableName,
		@childTableNameNoSchema = @childTableNameNoSchema,
		@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
		@childFieldNameToAdd = @childFieldNameToAdd,
		@deleteOldChildAlreadyLinkedField = 1,
		@deleteOldParentAlreadyLinkedField = 0,
		@relationNameToDelete = @relationNameToDelete,
		@relationToCreateNameOverride = @relationToCreateNameOverride,
		@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
		@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
		@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
		@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
		@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
		@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull

PRINT '  ' + CHAR(10) + ' '


	IF @showLogMessages = 1
		PRINT 'TABLE:  GUID add Foriegn Key (DocSessionGUID)  to LogWarningSummary'

	SET @childTableName = 'pal.LogWarningSummary'
	SET @childTableNameNoSchema = 'LogWarningSummary'
	SET @relationNameToDelete = 'FK_LogWarningSummary_LogDocSession'
	SET @relationToCreateNameOverride = 'FK_LogWarningSummary_LogDocSession'

	EXEC @return_value = [dbo].[ctcsp___3_AddAndReLinkChildTableGuidForeignKey]
		@showLogMessages = @showLogMessages,
		@parentTableName = @parentTableName,
		@parentTableNameNoSchema = @parentTableNameNoSchema,
		@parentAlreadyLinkedFieldName = @parentAlreadyLinkedFieldName,
		@parentExistingFieldToLinkTo =@parentExistingFieldToLinkTo,
		@childTableName = @childTableName,
		@childTableNameNoSchema = @childTableNameNoSchema,
		@childAlreadyLinkedFieldName = @childAlreadyLinkedFieldName,
		@childFieldNameToAdd = @childFieldNameToAdd,
		@deleteOldChildAlreadyLinkedField = 1,
		@deleteOldParentAlreadyLinkedField = 0,
		@relationNameToDelete = @relationNameToDelete,
		@relationToCreateNameOverride = @relationToCreateNameOverride,
		@foreignKeyCascadesUpdates = @foreignKeyCascadesUpdates,
		@foreignKeyCascadesDeletes  =@foreignKeyCascadesDeletes,
		@foreignKeyEnforceForReplication = @foreignKeyEnforceForReplication,
		@foreignKeyConstraintEnforced = @foreignKeyConstraintEnforced,
		@autoRenameNewChildFieldToDeletedLinkedChildField = @autoRenameNewChildFieldToDeletedLinkedChildField,
		@childNewFieldToLinkToParentAllowsNull = @childNewFieldToLinkToParentAllowsNull

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  LogDocSession rename Column GUID to ID'

		ALTER Table pal.LogDocSession DROP COLUMN  ID

		SET @childTableName = 'pal.LogDocSession'
		SET @childFieldNameToAdd = 'GUID'
		SET @childAlreadyLinkedFieldName = 'ID'

	    SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
		PRINT @command
		EXEC( @command );

PRINT '  ' + CHAR(10) + ' '


IF @showLogMessages = 1
		PRINT 'TABLE:  LogAddIn Adding GUID Primary Key'

	SET @tableName = 'pal.LogAddIn'
		SET @tableNameNoSchema = 'LogAddIn'
		SET @newFieldName = 'NewID'
		SET @newPKConstraintNameOverride = 'PK_LogAddIn'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  LogCrash Adding GUID Primary Key'

	SET @tableName = 'pal.LogCrash'
		SET @tableNameNoSchema = 'LogCrash'
		SET @newPKConstraintNameOverride = 'PK_LogCrash'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  LogDocumentProjChange Adding GUID Primary Key'

	SET @tableName = 'pal.LogDocumentProjChange'
		SET @tableNameNoSchema = 'LogDocumentProjChange'
		SET @newFieldName = 'NewID'
		SET @newPKConstraintNameOverride = 'PK_LogDocumentProjChange'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  LogElement Adding GUID Primary Key'

	SET @tableName = 'pal.LogElement'
		SET @tableNameNoSchema = 'LogElement'
		SET @newPKConstraintNameOverride = 'PK_LogElement'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  LogEvent Adding GUID Primary Key'

	SET @tableName = 'pal.LogEvent'
		SET @tableNameNoSchema = 'LogEvent'
		SET @newPKConstraintNameOverride = 'PK_LogEvent'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  LogLink Adding GUID Primary Key'

	SET @tableName = 'pal.LogLink'
		SET @tableNameNoSchema = 'LogLink'
		SET @newPKConstraintNameOverride = 'PK_LogLink'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  LogMachine Adding GUID Primary Key'

	SET @tableName = 'pal.LogMachine'
		SET @tableNameNoSchema = 'LogMachine'
		SET @newPKConstraintNameOverride = 'PK_LogMachine'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  LogPrint Adding GUID Primary Key'

	SET @tableName = 'pal.LogPrint'
		SET @tableNameNoSchema = 'LogPrint'
		SET @newPKConstraintNameOverride = 'PK_LogPrint'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  LogSummary Adding GUID Primary Key'

	SET @tableName = 'pal.LogSummary'
		SET @tableNameNoSchema = 'LogSummary'
		SET @newPKConstraintNameOverride = 'PK_LogSummary'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		Print 'TABLE:  LogViewType Adding GUID Primary Key'

	SET @tableName = 'pal.LogViewType'
		SET @tableNameNoSchema = 'LogViewType'
		SET @newPKConstraintNameOverride = 'PK_LogViewType'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		Print 'TABLE:  LogWarning Adding GUID Primary Key'

	SET @tableName = 'pal.LogWarning'
		SET @tableNameNoSchema = 'LogWarning'
		SET @newPKConstraintNameOverride = 'PK_LogWarning'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		Print 'TABLE:  LogWarningSummary Adding GUID Primary Key'

	SET @tableName = 'pal.LogWarningSummary'
		SET @tableNameNoSchema = 'LogWarningSummary'
		SET @newPKConstraintNameOverride = 'PK_LogWarningSummary'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
	PRINT 'TABLE:  LogAddIn rename NewID to ID'

	SET @childTableName = 'pal.LogAddIn'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogCrash rename NewID to ID'
	
	SET @childTableName = 'pal.LogCrash'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogElement rename NewID to ID'

	SET @childTableName = 'pal.LogElement'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogEvent rename NewID to ID'

	SET @childTableName = 'pal.LogEvent'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogLink rename NewID to ID'

	SET @childTableName = 'pal.LogLink'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogMachine rename NewID to ID'

	SET @childTableName = 'pal.LogMachine'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogPrint rename NewID to ID'

	SET @childTableName = 'pal.LogPrint'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogSummary rename NewID to ID'

	SET @childTableName = 'pal.LogSummary'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogViewType rename NewID to ID'

	SET @childTableName = 'pal.LogViewType'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogWarning rename NewID to ID'

	SET @childTableName = 'pal.LogWarning'
	SET @childFieldNameToAdd = 'NewID'
	SET @childAlreadyLinkedFieldName = 'ID'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '	

IF @showLogMessages = 1
	PRINT 'TABLE:  LogWarningSummary rename NewID to ID'

	SET @childTableName = 'pal.LogWarningSummary'

	SET @command = 'ALTER Table ' + @childTableName + '  DROP  Column  ' + @childAlreadyLinkedFieldName
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @childTableName + '.' + @childFieldNameToAdd + ''', ''' + @childAlreadyLinkedFieldName + ''', ''COLUMN'''
	PRINT @command

	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
		PRINT 'TABLE:  Setting - Adding GUID Primary Key'

	SET @tableName = 'pal.LogSetting'
		SET @tableNameNoSchema = 'LogSetting'
		SET @newFieldName = 'NewID'
		SET @newPKConstraintNameOverride = 'PK_LogSetting'

		EXEC @return_value = [dbo].[ctcsp___4_AddGUIDIdentityField]
			@showLogMessages = @showLogMessages,
			@tableName = @tableName,
			@tableNameNoSchema = @tableNameNoSchema,
			@newFieldName = @newFieldName,
			@makeNewFieldUniqueIndexed = 0,
			@makeNewUniqueIndexClustered = 1,
			@makeNewFieldSolePrimaryKey = 1,
			@makeNewPrimaryKeyNonClustered = 0,
			@newPKConstraintNameOverride = @newPKConstraintNameOverride

	SET @command = 'ALTER Table ' + @tableName + '  DROP  Column ID'
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @tableName + '.' + @newFieldName + ''', ''ID'', ''COLUMN'''
	EXEC(@command) ;
	PRINT @command

PRINT '  ' + CHAR(10) + ' '

IF @showLogMessages = 1
	PRINT 'TABLE:  LogDocumentProjChange - Renaming NewID to ID'

	SET @tableName = 'pal.LogDocumentProjChange'
	SET @tableNameNoSchema = 'LogDocumentProjChange'
	SET @newFieldName = 'NewID'

	SET @command = 'ALTER Table ' + @tableName + '  DROP  Column ID'
	PRINT @command
	EXEC(@command) ;

	SET @command = 'sp_rename ''' + @tableName + '.' + @newFieldName + ''', ''ID'', ''COLUMN'''
	PRINT @command
	EXEC(@command) ;

PRINT '  ' + CHAR(10) + ' '

PRINT 'TABLE:  Add Column CentralFilePath to LogSession'
SET @command = 'ALTER Table pal.LogDocSession Add CentralFilePath nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL;'
EXEC(@command) ;

SET @command = 'UPDATE  pal.LogDocSession SET CentralFilePath = Left(CentralFileName, LEN(CentralFileName) - CHARINDEX(''\'', REVERSE(CentralFileName), 1))'
EXEC(@command) ;

SET @command = 'UPDATE pal.LogDocSession SET CentralFilePath = '''' WHERE CentralFilePath IS NULL'
EXEC(@command) ;

SET @command = 'ALTER Table pal.LogDocSession ALTER COLUMN CentralFilePath nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL;'
EXEC(@command) ;

SET @command = 'Alter table pal.LogDocSession Add Status bit NOT NULL DEFAULT(1);'
EXEC(@command) ;


IF @showLogMessages = 1
	PRINT 'TABLE:  Drop Column LocalTimeOffset  from LogDocSession'
	Set @ConstraintName = ''
	Set @ConstraintName = (SELECT 
				df.name
		FROM 
			sys.default_constraints df
		INNER JOIN 
			sys.tables t ON df.parent_object_id = t.object_id
		INNER JOIN 
			sys.columns c ON c.object_id = df.parent_object_id AND df.parent_column_id = c.column_id
		WHERE 
			t.Name = N'LogDocSession'
			AND c.Name = N'LocalTimeOffset' )

	IF( @ConstraintName != '')
	BEGIN
		EXEC ('ALTER TABLE pal.LogDocSession DROP CONSTRAINT '  + @ConstraintName )

		IF EXISTS(SELECT *
			FROM   INFORMATION_SCHEMA.COLUMNS
			WHERE  TABLE_NAME = 'LogDocSession'
					AND COLUMN_NAME = 'LocalTimeOffset') 
		BEGIN
			EXEC ('ALTER TABLE pal.LogDocSession DROP COLUMN LocalTimeOffset')
		END
	END

IF @showLogMessages = 1
	PRINT 'TABLE:  Add  UNQ_LogMachine_LogDocSession to LogMachine'


	

	IF OBJECT_ID('pal.[UNQ_LogMachine_LogDocSession]', 'UQ') IS NULL 
	BEGIN
		ALTER TABLE [pal].[LogMachine] ADD  CONSTRAINT [UNQ_LogMachine_LogDocSession1] UNIQUE NONCLUSTERED 
		(
			[DocSessionID] ASC
		)
	END
	
	

PRINT 'PAL - Updating stored procedure for asset schema ctcsp_Project_ReadByAll'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Project_ReadByAll' )
		DROP PROCEDURE  asset.ctcsp_Project_ReadByAll
	EXEC('CREATE PROCEDURE [asset].[ctcsp_Project_ReadByAll]
	(
		@CompanyID int
	)
	AS
		SET NOCOUNT ON;
				
	SELECT ID,
			Office,
			ProjectNumber,
			ProjectName,
			BuildingName,
			ClientName,
			StreetAddress,
			StreetAddress2,
			StreetAddress3,
			ProjectPhase,
			ProjectIssueDate,
			Author,
			City,
			StateOrProvince,
			PostalCode,
			CountryName,
			OrgName,
			OrgDescription,
			ProjectImage,
			AddedDate
			UpdatedDate,
			CompanyID,
			AddedByUserID,
			UpdatedByUserID,
			Status
				   
	FROM asset.Project
	WHERE CompanyID = @CompanyID
' )		

PRINT 'PAL - Updating stored procedure for asset schema ctcsp_Project_ReadByClientName'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Project_ReadByClientName' )
		DROP PROCEDURE  asset.ctcsp_Project_ReadByClientName
	EXEC('CREATE PROCEDURE [asset].[ctcsp_Project_ReadByClientName]
	(
		@CompanyID int,
		@ClientName nvarchar(50)
	)
	AS
		SET NOCOUNT ON;
				
	SELECT ID,
			Office,
			ProjectNumber,
			ProjectName,
			BuildingName,
			ClientName,
			StreetAddress,
			StreetAddress2,
			StreetAddress3,
			ProjectPhase,
			ProjectIssueDate,
			Author,
			City,
			StateOrProvince,
			PostalCode,
			CountryName,
			OrgName,
			OrgDescription,
			ProjectImage,
			AddedDate
			UpdatedDate,
			CompanyID,
			AddedByUserID,
			UpdatedByUserID,
			Status
				   
	FROM asset.Project

	WHERE (ClientName = @ClientName)
	AND (CompanyID = @CompanyID)
' )		

PRINT 'PAL - Updating stored procedure for asset schema ctcsp_Project_ReadByProjectName'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Project_ReadByProjectName' )
		DROP PROCEDURE  asset.ctcsp_Project_ReadByProjectName
	EXEC('CREATE PROCEDURE [asset].[ctcsp_Project_ReadByProjectName]
	(
		@CompanyID int,
		@ProjectName nvarchar(255)
	)
	AS
		SET NOCOUNT ON;
				
	SELECT ID,
			Office,
			ProjectNumber,
			ProjectName,
			BuildingName,
			ClientName,
			StreetAddress,
			StreetAddress2,
			StreetAddress3,
			ProjectPhase,
			ProjectIssueDate,
			Author,
			City,
			StateOrProvince,
			PostalCode,
			CountryName,
			OrgName,
			OrgDescription,
			ProjectImage,
			AddedDate
			UpdatedDate,
			CompanyID,
			AddedByUserID,
			UpdatedByUserID,
			Status
				   
	FROM asset.Project
	
	WHERE(CompanyID = @CompanyID)
	AND (ProjectName = @ProjectName)
' )		

PRINT 'PAL - Updating stored procedure for asset schema ctcsp_Project_ReadByProjectNumber'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Project_ReadByProjectNumber' )
		DROP PROCEDURE  asset.ctcsp_Project_ReadByProjectNumber
	EXEC('CREATE PROCEDURE [asset].[ctcsp_Project_ReadByProjectNumber]
	(
		@CompanyID int,
		@ProjectNumber nvarchar(50)
	)
	AS
		SET NOCOUNT ON;
				
	SELECT ID,
			Office,
			ProjectNumber,
			ProjectName,
			BuildingName,
			ClientName,
			StreetAddress,
			StreetAddress2,
			StreetAddress3,
			ProjectPhase,
			ProjectIssueDate,
			Author,
			City,
			StateOrProvince,
			PostalCode,
			CountryName,
			OrgName,
			OrgDescription,
			ProjectImage,
			AddedDate
			UpdatedDate,
			CompanyID,
			AddedByUserID,
			UpdatedByUserID,
			Status
				   
	FROM asset.Project
	WHERE(CompanyID = @CompanyID)
	AND (ProjectNumber = @ProjectNumber)
' )	

PRINT 'PAL - Updating stored procedure for dbo ctcsp_Get_LogLinks_ByNamedDateRange'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogLinks_ByNamedDateRange' )
		DROP PROCEDURE  dbo.ctcsp_Get_LogLinks_ByNamedDateRange
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogLinks_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
				
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT [ID] As Id
			,[DocSessionID] As DocSessionId
			,[LinkPath]
			,[LinkShortFileName]
			,[LinkType]
			,[LinkStatus]
			,[UserName]
			,[LinksDateTime]
			,''''x'''' as CheckVal
			FROM pal.LogLink ''

			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''LinksDateTime'');

			EXEC(@sql + @where  + '' ORDER BY LinksDateTime'');

	END	
' )	


PRINT 'PAL - Updating stored procedure for dbo schema ctcsp_Get_LogLinks_ByNamedDateRange'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogLinks_ByNamedDateRange' )
		DROP PROCEDURE  dbo.ctcsp_Get_LogLinks_ByNamedDateRange
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogLinks_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
				
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT [ID] As Id
			,[DocSessionID] As DocSessionId
			,[LinkPath]
			,[LinkShortFileName]
			,[LinkType]
			,[LinkStatus]
			,[UserName]
			,[LinksDateTime]
			,''''x'''' as CheckVal
			FROM pal.LogLink ''

			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''LinksDateTime'');

			EXEC(@sql + @where  + '' ORDER BY LinksDateTime'');

	END	
' )	

PRINT 'PAL - Updating stored procedure for dbo schema ctcsp_Get_LogMachines_ByNamedDateRange'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogMachines_ByNamedDateRange' )
		DROP PROCEDURE  dbo.ctcsp_Get_LogMachines_ByNamedDateRange
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogMachines_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
		AS
		BEGIN
			SET NOCOUNT ON;
			
			DECLARE @sql varchar(1000)
			DECLARE @where varchar(1000)

			SET @sql = 
				''SELECT [ID] As Id
				,[DocSessionID] As DocSessionId
				,[ProcessorId]
				,[MachineName]
				,[MAC]
				,[OperatingSystem]
				,[HDD]
				,[Motherboard]
				,[Bios]
				,[RAM]
				,[RAM_Slots]
				,[CPU]
				,[Video]
				,[LogDateTime]
				,[IPAddress]
				FROM pal.ctcvw_Machines ''

				SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''LogDateTime'');

				EXEC(@sql + @where  + '' ORDER BY LogDateTime'');

		END 
' )

PRINT 'PAL - Updating stored procedure for dbo schema ctcsp_Get_LogViewTypes_ByNamedDateRange'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogViewTypes_ByNamedDateRange' )
		DROP PROCEDURE  dbo.ctcsp_Get_LogViewTypes_ByNamedDateRange
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_LogViewTypes_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
				
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1000)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT [ID] As Id
			,[DocSessionID] As DocSessionId
			,[ViewTypeName]
			,[ViewCt]
			,[ViewDateTime]
			,''''x'''' as CheckVal
			FROM pal.LogViewType ''

			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''ViewDateTime'');

			EXEC(@sql + @where  + '' ORDER BY ViewDateTime'');

	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogAddIn'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogAddIn' )
		DROP PROCEDURE  pal.ctcsp_Add_LogAddIn
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Add_LogAddIn]
	(
		@ResultCount int output,
		@DocSessionID uniqueidentifier,
		@Name nvarchar(255),
		@LogDateTime datetime
					
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
		BEGIN TRY			
			INSERT INTO [pal].LogAddIn (
				[DocSessionID],
				[Name],
				[LogDateTime]
					
			) 	
			VALUES (
				@DocSessionID,
				@Name,
				@LogDateTime
			);
			SET @ResultCount =  @@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER.  
			-- 2627 = Violation of PRIMARY KEY constraint
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH	
	END
    RETURN  @ResultCount
' )
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogCrash'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogCrash' )
		DROP PROCEDURE  pal.ctcsp_Add_LogCrash
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogCrash]
	(
		@ResultCount int output,
		@ID uniqueidentifier,
		@DocSessionID uniqueidentifier,
		@UserName nvarchar(100),
		@CentralFileName nvarchar(255),
		@LocalFileName nvarchar(255),
		@RevitVersion nvarchar(100),
		@LocalFileSize int,
		@Description nvarchar(255),
		@ExceptionDateTime datetime,
		@LogDateTime datetime
					
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
		BEGIN TRY		
		INSERT INTO [pal].LogCrash (
			[ID],
			[DocSessionID],
			[UserName],
			[CentralFileName],
			[LocalFileName],
			[RevitVersion],
			[LocalFileSize],
			[Description],
			[ExceptionDateTime],
			[LogDateTime]
		) 
				
		VALUES (
			@ID,
			@DocSessionID,
			@UserName,
			@CentralFileName,
			@LocalFileName,
			@RevitVersion,
			@LocalFileSize,
			@Description,
			@ExceptionDateTime,
			@LogDateTime
		);
		SET @ResultCount =  @@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER. 
			-- 2627 = Violation of PRIMARY KEY constraint 
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH	
	END
    RETURN  @ResultCount	
')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogDocSession'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogDocSession' )
		DROP PROCEDURE  pal.ctcsp_Add_LogDocSession
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogDocSession]
	(
		@ResultCount int output,
		@ID uniqueidentifier,
		@UserName nvarchar(100),
		@Server nvarchar(255),
		@CentralFileName nvarchar(255),
		@CentralFilePath nvarchar(255),
		@ShortFileName nvarchar(255),
		@LocalFileName nvarchar(255),
		@LocalFileSize int,
		@RevitVersion nvarchar(100),
		@IsAudit bit,
		@DocDateTime datetime,
		@LoadTime float,
		@STCDuration float,
		@STCDateTime datetime,
		@SessionHours float,
		@PhaseCt int,
		@DesOptCt int,
		@WorksetCt int,
		@ViewCt int,
		@GroupCt int,
		@FamilyCt int,
		@InstanceCt int,
		@UnplacedFamilyCt int,
		@InPlaceCt int,
		@UnPlacedRoomCt int,
		@UnenclosedRoomCt int,
		@PlacedRoomCt int,
		@UnPlacedSpaceCt int,
		@UnenclosedSpaceCt int,
		@PlacedSpaceCt int,
		@MaterialCt int,
		@ViewFilterCt int,
		@LevelCt int,
		@ElemAddedCt int,
		@ElemDeletedCt int,
		@ElemModifiedCt int,
		@WarningCt int,
		@HasClosed bit,
		@CompanyID int,
		@MachineName nvarchar(255),
		@BasePoint nvarchar(50),
		@SurveyPoint nvarchar(50),
		@AngleToTrueNorth float,
		@ProjectID int,
		@WorksetOpenCt int,
		@WorksetEditCt int,
		@SiteLatLong nvarchar(50),
		@Status bit
	)
	AS
	SET NOCOUNT OFF;
	
	BEGIN TRY
				
	INSERT INTO [pal].LogDocSession (
		[ID],
		[UserName],
		[Server],
		[CentralFileName],
		[CentralFilePath],
		[ShortFileName],
		[LocalFileName],
		[LocalFileSize],
		[RevitVersion],
		[IsAudit],
		[DocDateTime],
		[LoadTime],
		[STCDuration],
		[STCDateTime],
		[SessionHours],
		[PhaseCt],
		[DesOptCt],
		[WorksetCt],
		[ViewCt],
		[GroupCt],
		[FamilyCt],
		[InstanceCt],
		[UnplacedFamilyCt],
		[InPlaceCt],
		[UnPlacedRoomCt],
		[UnenclosedRoomCt],
		[PlacedRoomCt],
		[UnPlacedSpaceCt],
		[UnenclosedSpaceCt],
		[PlacedSpaceCt],
		[MaterialCt],
		[ViewFilterCt],
		[LevelCt],
		[ElemAddedCt],
		[ElemDeletedCt],
		[ElemModifiedCt],
		[WarningCt],
		[HasClosed],
		[CompanyID],
		[MachineName],
		[BasePoint],
		[SurveyPoint],
		[AngleToTrueNorth],
		[ProjectID],
		[WorksetOpenCt],
		[WorksetEditCt],
		[SiteLatLong],
		[Status]
	) 
				
	VALUES (
		@ID,
		@UserName,
		@Server,
		@CentralFileName,
		@CentralFilePath,
		@ShortFileName,
		@LocalFileName,
		@LocalFileSize,
		@RevitVersion,
		@IsAudit,
		@DocDateTime,
		@LoadTime,
		@STCDuration,
		@STCDateTime,
		@SessionHours,
		@PhaseCt,
		@DesOptCt,
		@WorksetCt,
		@ViewCt,
		@GroupCt,
		@FamilyCt,
		@InstanceCt,
		@UnplacedFamilyCt,
		@InPlaceCt,
		@UnPlacedRoomCt,
		@UnenclosedRoomCt,
		@PlacedRoomCt,
		@UnPlacedSpaceCt,
		@UnenclosedSpaceCt,
		@PlacedSpaceCt,
		@MaterialCt,
		@ViewFilterCt,
		@LevelCt,
		@ElemAddedCt,
		@ElemDeletedCt,
		@ElemModifiedCt,
		@WarningCt,
		@HasClosed,
		@CompanyID,
		@MachineName,
		@BasePoint,
		@SurveyPoint,
		@AngleToTrueNorth,
		@ProjectID,
		@WorksetOpenCt,
		@WorksetEditCt,
		@SiteLatLong,
		@Status
	);
		-- IF NO ERROR RETURN ROWS AFFECTED
		SET @ResultCount =  @@ROWCOUNT
	END TRY
	BEGIN CATCH
		-- RETURN ERROR NUMBER.  
		-- 2627 = Violation of PRIMARY KEY constraint
		-- 2601 =  Violation of UNIQUE INDEX
		SET @ResultCount = (SELECT ERROR_NUMBER())
	END CATCH	
	
    RETURN  @ResultCount
')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogElement'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogElement' )
		DROP PROCEDURE  pal.ctcsp_Add_LogElement
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogElement]
	(
		@ResultCount int output,
		@DocSessionID uniqueidentifier,
		@ElementId int,
		@ActionType int,
		@LogDateTime datetime
					
	)
	AS
	SET NOCOUNT OFF;
	BEGIN TRY		
	INSERT INTO [pal].LogElement (
		[DocSessionID],
		[ElementId],
		[ActionType],
		[LogDateTime]
	) 
				
	VALUES (
		@DocSessionID,
		@ElementId,
		@ActionType,
		@LogDateTime
	);
				
	SET @ResultCount=@@ROWCOUNT
	END TRY
	BEGIN CATCH
		-- RETURN ERROR NUMBER.  
		-- 2627 = Violation of PRIMARY KEY constraint
		-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
		--(LogDocSession does not contain a record with the correct primary key)
		SET @ResultCount = (SELECT ERROR_NUMBER())
		PRINT ERROR_MESSAGE()
	END CATCH	
	RETURN @ResultCount 
')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogEvent'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogEvent' )
		DROP PROCEDURE  pal.ctcsp_Add_LogEvent
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogEvent]
	(
		-- ID is auto generated
		@ResultCount int output,
		@DocSessionID uniqueidentifier,
		@EventId int,
		@EventType nvarchar (10),
		@EventName  nvarchar (25),
		@ViewName  nvarchar (100),
		@OpenViewCt int,
		@EventDateTime datetime,
		@EventDuration float,
		@ActionCt int,
		@ActiveWorksetName  nvarchar (255),
		@FamilyWorksetOpenCt int,
		@FamilyWorksetEditCt int,
		@StandardWorksetOpenCt int,
		@StandardWorksetEditCt int,
		@UserWorksetOpenCt int,
		@UserWorksetEditCt int,
		@ViewWorksetOpenCt int,
		@ViewWorksetEditCt int
					
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
		BEGIN TRY		
		INSERT INTO [pal].LogEvent (
			[DocSessionID],
			[EventId],
			[EventType],
			[EventName],
			[ViewName],
			[OpenViewCt],
			[EventDuration],
			[EventDateTime],
			[ActionCt],
			[ActiveWorksetName],
			[FamilyWorksetOpenCt],
			[FamilyWorksetEditCt],
			[StandardWorksetOpenCt],
			[StandardWorksetEditCt],
			[UserWorksetOpenCt],
			[UserWorksetEditCt],
			[ViewWorksetOpenCt],
			[ViewWorksetEditCt]
		) 
				
		VALUES (
			@DocSessionID,
			@EventId,
			@EventType,
			@EventName,
			@ViewName,
			@OpenViewCt,
			@EventDuration,
			@EventDateTime,
			@ActionCt,
			@ActiveWorksetName,
			@FamilyWorksetOpenCt,
			@FamilyWorksetEditCt,
			@StandardWorksetOpenCt,
			@StandardWorksetEditCt,
			@UserWorksetOpenCt,
			@UserWorksetEditCt,
			@ViewWorksetOpenCt,
			@ViewWorksetEditCt
		);
		SET @ResultCount=@@ROWCOUNT
		END TRY	
		BEGIN CATCH
			-- RETURN ERROR NUMBER. 
			-- 2627 = Violation of PRIMARY KEY constraint 
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH	
	END
	RETURN @ResultCount  

')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogLink'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogLink' )
		DROP PROCEDURE  pal.ctcsp_Add_LogLink
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogLink]
	(
		-- ID is auto generated
		@ResultCount int output,
		@DocSessionID uniqueidentifier,
		@UserName nvarchar(50),
		@LinkPath nvarchar(255),
		@LinkShortFileName nvarchar(255),
		@LinkType nvarchar(25),
		@LinkStatus nvarchar(25),
		@LinksDateTime datetime
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
		BEGIN TRY		
		INSERT INTO [pal].LogLink (
			[DocSessionID],
			[UserName],
			[LinkPath],
			[LinkShortFileName],
			[LinkType],
			[LinkStatus],
			[LinksDateTime]
		) 
				
		VALUES (
			@DocSessionID,
			@UserName,
			@LinkPath,
			@LinkShortFileName,
			@LinkType,
			@LinkStatus,
			@LinksDateTime
		);
				
		SET @ResultCount=@@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER. 
			-- 2627 = Violation of PRIMARY KEY constraint 
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH	
	END
    RETURN @ResultCount
')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogMachine'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogMachine' )
		DROP PROCEDURE  pal.ctcsp_Add_LogMachine
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogMachine]
	(
		-- ID is auto generated
		@ResultCount int output,
		@DocSessionID uniqueidentifier,
		@ProcessorId nvarchar(32),
		@MachineName nvarchar(255),
		@MAC nvarchar(18),
		@OperatingSystem nvarchar(255),
		@HDD nvarchar(max),
		@Motherboard nvarchar(255),
		@Bios nvarchar(255),
		@RAM int,
		@RAM_Slots int,
		@CPU nvarchar(max),
		@Video nvarchar(max),
		@IPAddress nvarchar(16),
		@LogDateTime datetime
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
		BEGIN TRY		
		INSERT INTO [pal].LogMachine(
			[DocSessionID],
			[ProcessorId],
			[MachineName],
			[MAC],
			[OperatingSystem],
			[HDD],
			[Motherboard],
			[Bios],
			[RAM],
			[RAM_Slots],
			[CPU],
			[Video],
			[IPAddress],
			[LogDateTime]
		) 
				
		VALUES (
			@DocSessionID,
			@ProcessorId,
			@MachineName,
			@MAC,
			@OperatingSystem,
			@HDD,
			@Motherboard,
			@Bios,
			@RAM,
			@RAM_Slots,
			@CPU,
			@Video,
			@IPAddress,
			@LogDateTime
		);
				
		SET @ResultCount=@@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER.  
			-- 2627 = Violation of PRIMARY KEY constraint
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH
	END	
	RETURN @ResultCount
')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogPrint'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogPrint' )
		DROP PROCEDURE  pal.ctcsp_Add_LogPrint
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogPrint]
	(
		-- ID is auto generated
		@ResultCount int output,
		@DocSessionID uniqueidentifier,
		@JobID int,
		@UserName nvarchar(100),
		@Printed nvarchar(max),
		@Failed nvarchar(max),
		@PrintCt int,
		@FailCt int,
		@JobStart datetime,
		@JobEnd datetime
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
		BEGIN TRY		
		INSERT INTO [pal].LogPrint (
			[DocSessionID],
			[JobID],
			[UserName],
			[Printed],
			[Failed],
			[PrintCt],
			[FailCt],
			[JobStart],
			[JobEnd]
		) 
				
		VALUES (
			@DocSessionID,
			@JobID,
			@UserName,
			@Printed,
			@Failed,
			@PrintCt,
			@FailCt,
			@JobStart,
			@JobEnd
		);
				
		SET @ResultCount=@@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER. 
			-- 2627 = Violation of PRIMARY KEY constraint 
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH
	END	
	RETURN @ResultCount
')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogSession'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogSession' )
		DROP PROCEDURE  pal.ctcsp_Add_LogSession
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogSession]
	(
	    @ResultCount int output,
		@ID  uniqueidentifier,
		@CompanyID int,
		@UserName  nvarchar(100),
		@RevitVersion  int,
		@MachineName  nvarchar(255),
		@StartDateTime  datetime
		
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier
	SET @Exists = (SELECT ID From pal.LogSession WHERE ID = @ID)
		
	IF @Exists IS NOT NULL
	BEGIN
		SET @ResultCount=1
	END
	ELSE
	BEGIN	
		BEGIN TRY		
		INSERT INTO [pal].LogSession (
			[ID],
			[CompanyID],
			[UserName],
			[RevitVersion],
			[MachineName],
			[StartDateTime]
		
		) 
				
		VALUES (
			@ID,
			@CompanyID,
			@UserName,
			@RevitVersion,
			@MachineName,
			@StartDateTime
		
		);
				
		SET @ResultCount=@@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER.  
			-- 2627 = Violation of PRIMARY KEY constraint
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH	
	END
	RETURN @ResultCount
')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogSetting'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogSetting' )
		DROP PROCEDURE  pal.ctcsp_Add_LogSetting
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogSetting]
	(
	    @ResultCount int output,
		@CompanyID int,
		@LogWarningsForPre2018 bit,
		@LogDetailedWarnings bit,
		@LogSummarizedWarnings bit,
		@LogDetailedElementChanges bit,
		@LogAddIns bit,
		@LogPrinting bit,
		@LogViewChange bit,
		@LogAuditFlag bit,
		@LogNonWorkshared bit,
		@InferProject bit
	)
	AS
		SET NOCOUNT OFF;
				
	INSERT INTO [pal].LogSetting (
		[CompanyID],
		[LogWarningsForPre2018],
		[LogDetailedWarnings],
		[LogSummarizedWarnings],
		[LogDetailedElementChanges],
		[LogAddIns],
		[LogPrinting],
		[LogViewChange],
		[LogAuditFlag],
		[LogNonWorkshared],
		[InferProject],
		[AddedDate],
		[AddedByUserID],
		[UpdatedDate],
		[UpdatedByUserID]
	) 
				
	VALUES (
		@CompanyID,
		@LogWarningsForPre2018,
		@LogDetailedWarnings,
		@LogSummarizedWarnings,
		@LogDetailedElementChanges,
		@LogAddIns,
		@LogPrinting,
		@LogViewChange,
		@LogAuditFlag,
		@LogNonWorkshared,
		@InferProject,
		GETUTCDATE(),
		0,
		GETUTCDATE(),
		0
	);
				
	SET @ResultCount=@@ROWCOUNT
	RETURN @ResultCount')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogSummary'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogSummary' )
		DROP PROCEDURE  pal.ctcsp_Add_LogSummary
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogSummary]
	(
		@ResultCount int output,
		@DocSessionID uniqueidentifier,
		@EventId int,
		@GroupCt int,
		@InPlaceCt int,
		@UnPlacedRoomCt int,
		@UnenclosedRoomCt int,
		@PlacedRoomCt int,
		@UnPlacedSpaceCt int,
		@UnenclosedSpaceCt int,
		@PlacedSpaceCt int,
		@ViewCt int,
		@PhaseCt int,
		@DesOptCt int,
		@WorksetCt int,
		@FamilyCt int,
		@InstanceCt int,
		@MaterialCt int,
		@ViewFilterCt int,
		@UnplacedFamilyCt int,
		@LevelCt int,
		@WarningCt int,
		@SummaryDateTime datetime
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
	BEGIN TRY		
		INSERT INTO [pal].LogSummary (
			[DocSessionID],
			[EventId],
			[GroupCt],
			[InPlaceCt],
			[UnPlacedRoomCt],
			[UnenclosedRoomCt],
			[PlacedRoomCt],
			[UnPlacedSpaceCt],
			[UnenclosedSpaceCt],
			[PlacedSpaceCt],
			[ViewCt],
			[PhaseCt],
			[DesOptCt],
			[WorksetCt],
			[FamilyCt],
			[InstanceCt],
			[MaterialCt],
			[ViewFilterCt],
			[UnplacedFamilyCt],
			[LevelCt],
			[WarningCt],
			[SummaryDateTime]
		) 
				
		VALUES (
			@DocSessionID,
			@EventId,
			@GroupCt,
			@InPlaceCt,
			@UnPlacedRoomCt,
			@UnenclosedRoomCt,
			@PlacedRoomCt,
			@UnPlacedSpaceCt,
			@UnenclosedSpaceCt,
			@PlacedSpaceCt,
			@ViewCt,
			@PhaseCt,
			@DesOptCt,
			@WorksetCt,
			@FamilyCt,
			@InstanceCt,
			@MaterialCt,
			@ViewFilterCt,
			@UnplacedFamilyCt,
			@LevelCt,
			@WarningCt,
			@SummaryDateTime
		);
				
		SET @ResultCount=@@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER.  
			-- 2627 = Violation of PRIMARY KEY constraint
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH	
	END
	RETURN @ResultCount  

' )
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogViewType'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogViewType' )
		DROP PROCEDURE  pal.ctcsp_Add_LogViewType
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogViewType]
	(
		-- ID is auto generated
		@ResultCount int output,
		@DocSessionID uniqueidentifier,
		@ViewTypeName nvarchar(25),
		@ViewCt int,
		@ViewDateTime datetime
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
		BEGIN TRY		
		INSERT INTO [pal].LogViewType(
			[DocSessionID],
			[ViewTypeName],
			[ViewCt],
			[ViewDateTime]
					
		) 
				
		VALUES (
			@DocSessionID,
			@ViewTypeName,
			@ViewCt,
			@ViewDateTime
		);
				
		SET @ResultCount=@@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER.
			-- 2627 = Violation of PRIMARY KEY constraint  
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH	
	END
    RETURN @ResultCount 
')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogWarning'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogWarning' )
		DROP PROCEDURE  pal.ctcsp_Add_LogWarning
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogWarning]
	(
		-- ID is auto generated
		@ResultCount int output,
		@DocSessionID uniqueidentifier,	
		@Severity nvarchar(25),
		@WarningId uniqueidentifier,
		@Description nvarchar(255),
		@ElementId int,
		@ElementName nvarchar(255),
		@LevelName nvarchar(255),
		@Workset nvarchar(255),
		@WarningDateTime datetime
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
		BEGIN TRY	
		INSERT INTO [pal].LogWarning(
			[DocSessionID],	
			[Severity],
			[WarningId],
			[Description],
			[ElementId],
			[ElementName],
			[LevelName],
			[Workset],
			[WarningDateTime]
		) 
				
		VALUES (
			@DocSessionID,	
			@Severity,
			@WarningId,
			@Description,
			@ElementId,
			@ElementName,
			@LevelName,
			@Workset,
			@WarningDateTime
		);
		SET @ResultCount=@@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER.  
			-- 2627 = Violation of PRIMARY KEY constraint
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH			
	END
    RETURN @ResultCount 

')
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Add_LogWarningSummary'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Add_LogWarningSummary' )
		DROP PROCEDURE  pal.ctcsp_Add_LogWarningSummary
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Add_LogWarningSummary]
	(
		-- ID is auto generated
		@ResultCount int output,
		@DocSessionID uniqueidentifier,
		@ElementIds nvarchar(max),
		@Description varchar(255),
		@LogDateTime datetime
					
	)
	AS
	SET NOCOUNT OFF;
	DECLARE @Exists uniqueidentifier

	SET @Exists = (SELECT ID From pal.LogDocSession WHERE ID = @DocSessionID)
		
	IF @Exists IS NULL
	BEGIN
		SET @ResultCount=0
	END
	ELSE
	BEGIN
		BEGIN TRY		
		INSERT INTO [pal].LogWarningSummary (
			[DocSessionID],
			[ElementIds],
			[Description],
			[LogDateTime]
		) 
				
		VALUES (
			@DocSessionID,
			@ElementIds,
			@Description,
			@LogDateTime
		);
				
		SET @ResultCount=@@ROWCOUNT
		END TRY
		BEGIN CATCH
			-- RETURN ERROR NUMBER.  
			-- 2627 = Violation of PRIMARY KEY constraint
			-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
			--(LogDocSession does not contain a record with the correct primary key)
			SET @ResultCount = (SELECT ERROR_NUMBER())
			PRINT ERROR_MESSAGE()
		END CATCH	
	END	
    RETURN @ResultCount 
')

	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Del_LogDocSession_ByID'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Del_LogDocSession_ByID' )
		DROP PROCEDURE  pal.ctcsp_Del_LogDocSession_ByID
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Del_LogDocSession_ByID]
	(
	    @ResultCount int output,
		@ID uniqueidentifier
	)
	AS
	BEGIN
		SET NOCOUNT OFF;
		
		DELETE FROM [pal].[LogDocSession] 

		WHERE (([ID] = @ID))

	SET @ResultCount=@@ROWCOUNT
	RETURN @ResultCount

	END	 
' ) 


PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Current_AddIn'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Current_AddIn' )
		DROP PROCEDURE  pal.ctcsp_Get_Current_AddIn
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_Current_AddIn]
		@p_CompanyID int
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SELECT 
			pal.LogDocSession.MachineName, 
			pal.LogDocSession.RevitVersion,
			pal.LogAddIn.Name AS AppName, 
			MAX(pal.LogAddIn.LogDateTime)
		FROM pal.LogDocSession 
			INNER JOIN pal.LogAddIn 
				ON pal.LogDocSession.ID = pal.LogAddIn.DocSessionID
		WHERE pal.LogDocSession.CompanyID = @p_CompanyID
		GROUP BY 
			pal.LogDocSession.MachineName,
			pal.LogDocSession.RevitVersion, 
			pal.LogAddIn.Name
		ORDER BY 
			pal.LogDocSession.MachineName, 
			pal.LogDocSession.RevitVersion,
			pal.LogAddIn.Name
	END 
' )


PRINT 'PAL - Updating stored procedure for pal schema [ctcsp_Get_DistinctProjectPaths'

	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_DistinctProjectPaths' )
		DROP PROCEDURE  pal.ctcsp_Get_DistinctProjectPaths
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_DistinctProjectPaths] 
	(
		@p_CompanyID int
	)	
	AS
	BEGIN

		SELECT DISTINCT
			ISNULL(pp.ID, 0) AS ID
			,s.CentralFilePath As CentralFileNameOrFolder
			,ISNULL(pr.ProjectNumber, ''unassigned'') AS ProjectNumber
			,pr.ID AS ProjectID
		FROM pal.LogDocSession AS s 
			LEFT OUTER JOIN asset.Project AS pr 
			INNER JOIN asset.ProjectPath AS pp ON pr.ID = pp.ProjectID
			ON s.CentralFilePath = pp.CentralFilePath 
					
		WHERE (s.CompanyID = @p_CompanyID) 
			
		ORDER BY ProjectNumber, CentralFileNameOrFolder

		END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogDocSessions'

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogDocSessions' )
		DROP PROCEDURE  pal.ctcsp_Get_Last_LogDocSessions
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogDocSessions]
	(
		@CompanyID int,
		@Date DateTime
	)
	AS
	BEGIN
			
		SET NOCOUNT ON;
		
		SELECT  
				Data.ID,  
				Data.ProjectID,  
				Data.CompanyID,  
				asset.Project.ProjectNumber,  
				asset.Project.ProjectName,  
				asset.Project.ClientName,  
				UserName,  
				[Server],  
				CentralFileName, 
				CentralFilePath, 
				ShortFileName,  
				LocalFileName,  
				LocalFileSize,  
				RevitVersion,  
				IsAudit,  
				DocDateTime,  
				STCDateTime,  
				LoadTime,  
				STCDuration,  
				SessionHours,  
				GroupCt,  
				InPlaceCt,  
				UnPlacedRoomCt,  
				UnenclosedRoomCt,  
				PlacedRoomCt,  
				UnPlacedSpaceCt,  
				UnenclosedSpaceCt,  
				PlacedSpaceCt,  
				ViewCt,  
				PhaseCt,  
				DesOptCt,  
				WorksetCt,  
				Data.WorksetEditCt,  
				WorksetOpenCt,  
				FamilyCt,  
				InstanceCt,  
				UnplacedFamilyCt,  
				MaterialCt,  
				ViewFilterCt,  
				LevelCt,  
				ElemAddedCt,  
				ElemDeletedCt,  
				ElemModifiedCt,  
				WarningCt,  
				MachineName,  
				BasePoint,  
				SurveyPoint,  
				AngleToTrueNorth,  
				SiteLatLong,  
				HasClosed  
			FROM (pal.LogDocSession AS Data INNER JOIN asset.Project ON ProjectID = asset.Project.ID)  
			WHERE ([DocDateTime] =  
			(SELECT MAX([DocDateTime]) AS Expr1  
				FROM pal.LogDocSession AS LogDocSession_1  
					WHERE ([CentralFileName] = Data.[CentralFileName])  
					AND (STCDuration > 0)) 
				AND (Data.CompanyID = @CompanyID ) 
				AND (Data.DocDateTime >= @Date ))
		ORDER BY Data.DocDateTime ASC

		 
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessions'

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessions' )
		DROP PROCEDURE  pal.ctcsp_Get_LogDocSessions
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_LogDocSessions]
	(
		@CompanyID int, 
		@Date datetime
	)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT
			[ID],
			[UserName],
			[Server],
			[CentralFileName],
			[CentralFilePath],
			[ShortFileName],
			[LocalFileName],
			[LocalFileSize],
			[RevitVersion],
			[IsAudit],
			[DocDateTime],
			[LoadTime],
			[STCDuration],
			[STCDateTime],
			[SessionHours],
			[PhaseCt],
			[DesOptCt],
			[WorksetCt],
			[ViewCt],
			[GroupCt],
			[FamilyCt],
			[InstanceCt],
			[UnplacedFamilyCt],
			[InPlaceCt],
			[UnPlacedRoomCt],
			[UnenclosedRoomCt],
			[PlacedRoomCt],
			[UnPlacedSpaceCt],
			[UnenclosedSpaceCt],
			[PlacedSpaceCt],
			[MaterialCt],
			[ViewFilterCt],
			[LevelCt],
			[ElemAddedCt],
			[ElemDeletedCt],
			[ElemModifiedCt],
			[WarningCt],
			[HasClosed],
			[CompanyID],
			--[LocalTimeOffset],
			[MachineName],
			[BasePoint],
			[SurveyPoint],
			[AngleToTrueNorth],
			[ProjectID],
			[WorksetOpenCt],
			[WorksetEditCt],
			[SiteLatLong],
			[Status]
		FROM pal.LogDocSession 
		WHERE ( CompanyID = @CompanyID ) 
		ORDER BY [DocDateTime], [LocalFileName]
		END
	ELSE
		BEGIN
			SELECT
			[ID],
			[UserName],
			[Server],
			[CentralFileName],
			[CentralFilePath],
			[ShortFileName],
			[LocalFileName],
			[LocalFileSize],
			[RevitVersion],
			[IsAudit],
			[DocDateTime],
			[LoadTime],
			[STCDuration],
			[STCDateTime],
			[SessionHours],
			[PhaseCt],
			[DesOptCt],
			[WorksetCt],
			[ViewCt],
			[GroupCt],
			[FamilyCt],
			[InstanceCt],
			[UnplacedFamilyCt],
			[InPlaceCt],
			[UnPlacedRoomCt],
			[UnenclosedRoomCt],
			[PlacedRoomCt],
			[UnPlacedSpaceCt],
			[UnenclosedSpaceCt],
			[PlacedSpaceCt],
			[MaterialCt],
			[ViewFilterCt],
			[LevelCt],
			[ElemAddedCt],
			[ElemDeletedCt],
			[ElemModifiedCt],
			[WarningCt],
			[HasClosed],
			[CompanyID],
			--[LocalTimeOffset],
			[MachineName],
			[BasePoint],
			[SurveyPoint],
			[AngleToTrueNorth],
			[ProjectID],
			[WorksetOpenCt],
			[WorksetEditCt],
			[SiteLatLong],
			[Status]
		FROM pal.LogDocSession 
			WHERE ( CompanyID = @CompanyID ) 
			AND ( [DocDateTime] >= @Date ) 
			ORDER BY [DocDateTime], [LocalFileName]
		END
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessionsWithConflictingProjectIds'

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithConflictingProjectIds' )
		DROP PROCEDURE  pal.ctcsp_Get_LogDocSessionsWithConflictingProjectIds
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithConflictingProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		SELECT  s.ID, 
				s.CentralFileName, 
				s.ShortFileName, 
				s.ProjectID AS DocProjectID, 
				asset.Project.ProjectNumber AS DocProjectNumber, 
				pp.ProjectID AS ProjProjectID, 
				pr.ProjectNumber AS ProjProjectNumber, 
				s.DocDateTime, 
				pp.AddedDate AS ProjDateTime 
		FROM    pal.LogDocSession AS s
			INNER JOIN asset.ProjectPath AS pp
				ON	s.CentralFilePath = pp.CentralFilePath 
					AND s.ProjectID <> pp.ProjectID 
					INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
					INNER JOIN asset.Project ON s.ProjectID = asset.Project.ID
		WHERE   (s.CompanyID = @p_CompanyID)
		AND     (pr.CompanyID = @p_CompanyID)
		ORDER BY s.CentralFileName, s.ProjectID, s.DocDateTime, pp.AddedDate
			
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessionsWithDeletedProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithDeletedProjectIds' )
		DROP PROCEDURE  pal.ctcsp_Get_LogDocSessionsWithDeletedProjectIds
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithDeletedProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN
	SET NOCOUNT ON;
			
		SELECT 
			s.ID,
			s.CentralFileName, 
			s.ShortFileName,
			s.ProjectID AS DocProjectID,
			''deleted'' AS DocProjectNumber,
			pp.ProjectID AS ProjProjectID, 
			pr.ProjectNumber AS ProjProjectNumber,
			s.DocDateTime,
			pp.AddedDate AS ProjDateTime
		FROM pal.LogDocSession AS s
		LEFT JOIN asset.Project As p ON p.ID = s.ProjectID 
		INNER JOIN asset.ProjectPath As pp 
			ON s.CentralFilePath  = pp.CentralFilePath
		INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
		WHERE   (s.CompanyID = @p_CompanyID) 
		AND     (pr.CompanyID = @p_CompanyID)
		AND		(p.ID IS NULL)
		ORDER BY CentralFileName, DocProjectID, DocDateTime, ProjDateTime
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessionsWithEmptyProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithEmptyProjectIds' )
		DROP PROCEDURE  pal.ctcsp_Get_LogDocSessionsWithEmptyProjectIds
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithEmptyProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		SELECT  
			s.ID,       
			s.CentralFileName, 
			s.ShortFileName, 
			0 AS DocProjectID, 
			pr.ProjectNumber AS DocProjectNumber, 
			pp.ProjectID AS ProjProjectID, 
			pr.ProjectNumber AS ProjProjectNumber, 
			s.DocDateTime,
			pp.AddedDate AS ProjDateTime 
		FROM pal.LogDocSession AS s
			INNER JOIN
				asset.ProjectPath As pp ON 
				s.CentralFilePath = pp.CentralFilePath
				AND s.ProjectID is null
				INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
		WHERE (s.CompanyID = @p_CompanyID) 
		AND   (s.ProjectID IS NULL)
		ORDER BY CentralFileName, DocProjectID, DocDateTime, ProjDateTime
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessionsWithNoProject'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithNoProject' )
		DROP PROCEDURE  pal.ctcsp_Get_LogDocSessionsWithNoProject
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithNoProject] 
	(
		@p_CompanyID int
	)	
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

	SELECT distinct
		s.CentralFilePath As CentralFileName
	FROM pal.LogDocSession AS s 
		LEFT OUTER JOIN asset.Project AS pr 
		INNER JOIN asset.ProjectPath AS pp ON pr.ID = pp.ProjectID 
		ON s.CentralFilePath = pp.CentralFilePath 
		AND s.ProjectID <> pp.ProjectID
	WHERE (s.CompanyID = @p_CompanyID) 
	
	AND (s.ProjectID IS NULL) 
	AND (pp.ProjectID IS NULL)
	ORDER BY CentralFileName

	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds' )
		DROP PROCEDURE  pal.ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds] 
	(
		@p_CompanyID int
	)	
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		SELECT        
			s.ID,
			s.CentralFileName,
			s.ShortFileName, 
			s.ProjectID AS DocProjectID, 
			asset.Project.ProjectNumber AS DocProjectNumber, 
			pp.ProjectID AS ProjProjectID, 
			pr.ProjectNumber AS ProjProjectNumber, 
			s.DocDateTime,
			pp.AddedDate AS ProjDateTime
		FROM pal.LogDocSession As s
			INNER JOIN
				asset.ProjectPath As pp
				ON s.CentralFilePath = pp.CentralFilePath 
				AND s.ProjectID <> pp.ProjectID 
			INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
			INNER JOIN asset.Project ON s.ProjectID = asset.Project.ID
		WHERE (s.CompanyID = @p_CompanyID) 
		AND   (pr.CompanyID = @p_CompanyID)
		AND (s.ProjectID IS NOT NULL)
		ORDER BY CentralFileName, DocProjectID, DocDateTime, ProjDateTime

	END
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_MappedProjectPathsFromLogDocSessions'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_MappedProjectPathsFromLogDocSessions' )
		DROP PROCEDURE  pal.[ctcsp_Get_MappedProjectPathsFromLogDocSessions]
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_MappedProjectPathsFromLogDocSessions] 
	(
		@p_CompanyID int
	)	
	AS
	BEGIN

		SELECT DISTINCT
			pp.ID
			,s.CentralFilePath As CentralFileName
			,pr.ProjectNumber AS DocProjectNumber
			,pr.ID AS DocProjectID
		FROM pal.LogDocSession AS s 
			LEFT OUTER JOIN asset.Project AS pr 
			INNER JOIN asset.ProjectPath AS pp ON pr.ID = pp.ProjectID
			ON s.CentralFilePath = pp.CentralFilePath 
				
		WHERE (s.CompanyID = @p_CompanyID) 
		AND   (pr.CompanyID = @p_CompanyID) 
		AND   (pp.ProjectID IS NOT NULL)
		ORDER BY DocProjectNumber, CentralFileName

	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_ProjectPathsFromLogDocSessions'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_ProjectPathsFromLogDocSessions' )
		DROP PROCEDURE  pal.[ctcsp_Get_ProjectPathsFromLogDocSessions]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_ProjectPathsFromLogDocSessions]
	(
		@p_CompanyID int
	)	 
	AS
	BEGIN
			
		SET NOCOUNT ON;

		SELECT DISTINCT
			ISNULL(pp.ID, 0) AS ID
			,s.CentralFilePath As CentralFileName
			,ISNULL(pr.ProjectNumber, ''0'') AS DocProjectNumber
			,ISNULL(pr.ID, 0)  AS DocProjectID
		FROM pal.LogDocSession As s
			LEFT OUTER JOIN asset.Project AS pr 
			INNER JOIN asset.ProjectPath As pp ON pr.ID = pp.ProjectID
			ON s.CentralFilePath  = pp.CentralFilePath 
			AND s.ProjectID <> pp.ProjectID
		WHERE (s.CompanyID = @p_CompanyID) 
		ORDER BY CentralFileName

	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSession'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSession' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSession]
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Upd_LogDocSession]
	(
	    @ResultCount int output,
		@ID uniqueidentifier,
		@STCDuration float,
		@STCDateTime datetime,
		@SessionHours float,
		@PhaseCt int,
		@DesOptCt int,
		@ViewCt int,
		@GroupCt int,
		@FamilyCt int,
		@InstanceCt int,
		@UnplacedFamilyCt int,
		@InPlaceCt int,
		@UnPlacedRoomCt int,
		@UnenclosedRoomCt int,
		@PlacedRoomCt int,
		@UnPlacedSpaceCt int,
		@UnenclosedSpaceCt int,
		@PlacedSpaceCt int,
		@MaterialCt int,
		@ViewFilterCt int,
		@LevelCt int,
		@ElemAddedCt int,
		@ElemDeletedCt int,
		@ElemModifiedCt int,
		@WarningCt int,
		@HasClosed bit,
		@Status bit
	)
	AS
		SET NOCOUNT OFF;
	BEGIN TRY		
	UPDATE [pal].[LogDocSession] SET 
			[STCDuration] = @STCDuration,
			[STCDateTime] = @STCDateTime,
			[SessionHours] = @SessionHours,
			[PhaseCt] = @PhaseCt,
			[DesOptCt] = @DesOptCt,
			[ViewCt] = @ViewCt,
			[GroupCt] = @GroupCt,
			[FamilyCt] = @FamilyCt,
			[InstanceCt] = @InstanceCt,
			[UnplacedFamilyCt] = @UnplacedFamilyCt,
			[InPlaceCt] = @InPlaceCt,
			[UnPlacedRoomCt] = @UnPlacedRoomCt,
			[UnenclosedRoomCt] = @UnenclosedRoomCt,
			[PlacedRoomCt] = @PlacedRoomCt,
			[UnPlacedSpaceCt] = @UnPlacedSpaceCt,
			[UnenclosedSpaceCt] = @UnenclosedSpaceCt,
			[PlacedSpaceCt] = @PlacedSpaceCt,
			[MaterialCt] = @MaterialCt,
			[ViewFilterCt] = @ViewFilterCt,
			[LevelCt] = @LevelCt,
			[ElemAddedCt] = @ElemAddedCt,
			[ElemDeletedCt] = @ElemDeletedCt,
			[ElemModifiedCt] = @ElemModifiedCt,
			[WarningCt] = @WarningCt,
			[HasClosed] = @HasClosed,
			[Status] = @Status
		WHERE (([ID] = @ID));
		
		SET @ResultCount=@@ROWCOUNT
	END TRY
	BEGIN CATCH
		-- RETURN ERROR NUMBER.  
		-- 2627 = Violation of PRIMARY KEY constraint
		-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
		--(LogDocSession does not contain a record with the correct primary key)
		SET @ResultCount = (SELECT ERROR_NUMBER())
		PRINT ERROR_MESSAGE()
	END CATCH		
	RETURN @ResultCount 
' )


PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogEvents'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogEvents' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogEvents]
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_LogEvents]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  pal.LogEvent.[ID],
			[DocSessionID],
			[EventId],
			[EventType],
			[EventName],
			[ViewName],
			[OpenViewCt],
			[EventDateTime],
			[EventDuration],
			[ActionCt],
			[ActiveWorksetName],
			[FamilyWorksetOpenCt],
			[FamilyWorksetEditCt],
			[StandardWorksetOpenCt],
			[StandardWorksetEditCt],
			[UserWorksetOpenCt],
			[UserWorksetEditCt],
			[ViewWorksetOpenCt],
			[ViewWorksetEditCt]
		FROM pal.LogEvent 
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
		ORDER BY [EventDateTime], [EventId]
		END
	ELSE
		BEGIN
			SELECT pal.LogEvent.[ID],
			[DocSessionID],
			[EventId],
			[EventType],
			[EventName],
			[ViewName],
			[OpenViewCt],
			[EventDateTime],
			[EventDuration],
			[ActionCt],
			[ActiveWorksetName],
			[FamilyWorksetOpenCt],
			[FamilyWorksetEditCt],
			[StandardWorksetOpenCt],
			[StandardWorksetEditCt],
			[UserWorksetOpenCt],
			[UserWorksetEditCt],
			[ViewWorksetOpenCt],
			[ViewWorksetEditCt]

			FROM pal.LogEvent 
			INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			AND ( [EventDateTime] >= @Date ) 
			ORDER BY [EventDateTime], [EventId]
		END
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogEventsByEventName'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogEventsByEventName' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogEventsByEventName]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogEventsByEventName]
(
	@CompanyID int, 
	@Date datetime,
	@EventName NVARCHAR(25)
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  pal.LogEvent.[ID],
			[DocSessionID],
			[EventId],
			[EventType],
			[EventName],
			[ViewName],
			[OpenViewCt],
			[EventDateTime],
			[EventDuration],
			[ActionCt],
			[ActiveWorksetName],
			[FamilyWorksetOpenCt],
			[FamilyWorksetEditCt],
			[StandardWorksetOpenCt],
			[StandardWorksetEditCt],
			[UserWorksetOpenCt],
			[UserWorksetEditCt],
			[ViewWorksetOpenCt],
			[ViewWorksetEditCt]
		FROM pal.LogEvent 
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			  AND ( EventName = @EventName )
			  AND ( STCDuration > 0 )
		ORDER BY [EventDateTime], [EventId]
		END
	ELSE
		BEGIN
			SELECT pal.LogEvent.[ID],
			[DocSessionID],
			[EventId],
			[EventType],
			[EventName],
			[ViewName],
			[OpenViewCt],
			[EventDateTime],
			[EventDuration],
			[ActionCt],
			[ActiveWorksetName],
			[FamilyWorksetOpenCt],
			[FamilyWorksetEditCt],
			[StandardWorksetOpenCt],
			[StandardWorksetEditCt],
			[UserWorksetOpenCt],
			[UserWorksetEditCt],
			[ViewWorksetOpenCt],
			[ViewWorksetEditCt]
		FROM pal.LogEvent 
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			  AND ( EventName = @EventName )
			  AND ( STCDuration > 0 )
			  AND ( [EventDateTime] >= @Date ) 
			ORDER BY [EventDateTime], [EventId]
		END
	END 
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogEventsShort'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogEventsShort' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogEventsShort]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogEventsShort]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  
			pal.LogEvent.[ID],
			[DocSessionID],
			[EventName],
			[ViewName],
			[EventDateTime],
			[EventDuration]
		FROM pal.LogEvent 
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
		ORDER BY [EventDateTime], [EventId]
		END
	ELSE
		BEGIN
			SELECT 
			pal.LogEvent.[ID],
			[DocSessionID],
			[EventName],
			[ViewName],
			[EventDateTime],
			[EventDuration]

			FROM pal.LogEvent 
			INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			AND ( [EventDateTime] >= @Date ) 
			ORDER BY [EventDateTime], [EventId]
		END
	END 
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogEventsShortByEventName'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogEventsShortByEventName' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogEventsShortByEventName]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogEventsShortByEventName]
(
	@CompanyID int, 
	@Date datetime,
	@EventName NVARCHAR(25)
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  
			pal.LogEvent.[ID],
			[DocSessionID],
			[EventName],
			[ViewName],
			[EventDateTime],
			[EventDuration]
		FROM pal.LogEvent 
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			  AND ( EventName = @EventName )
			  AND ( STCDuration > 0 )
		ORDER BY [EventDateTime], [EventId]
		END
	ELSE
		BEGIN
			SELECT 
			pal.LogEvent.[ID],
			pal.LogEvent.[ID],
			[DocSessionID],
			[EventName],
			[ViewName],
			[EventDateTime],
			[EventDuration]
		FROM pal.LogEvent 
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			  AND ( EventName = @EventName )
			  AND ( STCDuration > 0 )
			  AND ( [EventDateTime] >= @Date ) 
			ORDER BY [EventDateTime], [EventId]
		END
	END 
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogLinks'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogLinks' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogLinks]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogLinks]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT 
			pal.LogLink.[ID],
			[DocSessionID],
			[LinkPath],
			[LinkShortFileName],
			[LinkType],
			[LinkStatus],
			pal.LogLink.[UserName],
			[LinksDateTime]
		FROM pal.LogLink
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
		ORDER BY [LinksDateTime], [LinkShortFileName]
		END
	ELSE
		BEGIN
			SELECT 
				pal.LogLink.[ID],
				[DocSessionID],
				[LinkPath],
				[LinkShortFileName],
				[LinkType],
				[LinkStatus],
				pal.LogLink.[UserName],
				[LinksDateTime]
			FROM pal.LogLink
			INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			AND ( [LinksDateTime] >= @Date ) 
			ORDER BY [LinksDateTime], [LinkShortFileName]
		END
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogMachines'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogMachines' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogMachines]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogMachines]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  
			pal.LogMachine.[ID],
			[DocSessionID],
			[ProcessorId],
			pal.LogMachine.[MachineName],
			[MAC],
			[OperatingSystem],
			[HDD],
			[Motherboard],
			[Bios],
			[RAM],
			[RAM_Slots],
			[CPU],
			[Video],
			[LogDateTime],
			[IPAddress]
			
		FROM pal.LogMachine
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
		ORDER BY [LogDateTime], pal.LogMachine.[MachineName]
		END
	ELSE
		BEGIN
			SELECT  
				pal.LogMachine.[ID],
				[DocSessionID],
				[ProcessorId],
				pal.LogMachine.[MachineName],
				[MAC],
				[OperatingSystem],
				[HDD],
				[Motherboard],
				[Bios],
				[RAM],
				[RAM_Slots],
				[CPU],
				[Video],
				[LogDateTime],
				[IPAddress]
				
			FROM pal.LogMachine
			INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			AND ( [LogDateTime] >= @Date ) 
			ORDER BY [LogDateTime], pal.LogMachine.[MachineName]
		END
	END 
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogPrints'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogPrints' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogPrints]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogPrints]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  
			pal.LogPrint.[ID],
			[DocSessionID],
			[JobID],
			pal.LogPrint.[UserName],
			[Printed],
			[Failed],
			[PrintCt],
			[FailCt],
			[JobStart],
			[JobEnd]
			
		FROM pal.LogPrint
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
		ORDER BY [JobStart], [UserName]
		END
	ELSE
		BEGIN
			SELECT  
				pal.LogPrint.[ID],
				[DocSessionID],
				[JobID],
				pal.LogPrint.[UserName],
				[Printed],
				[Failed],
				[PrintCt],
				[FailCt],
				[JobStart],
				[JobEnd]
				
			FROM pal.LogPrint
			INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			AND ( [JobStart] >= @Date ) 
			ORDER BY [JobStart], [UserName]
		END
	END 
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogSessions'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogSessions' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogSessions]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogSessions]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  
			[ID],
			[CompanyID],
			[UserName],
			[RevitVersion],
			[MachineName],
			[StartDateTime],
			[EndDateTime]
		FROM pal.LogSession
		WHERE ( CompanyID = @CompanyID )
		ORDER BY [StartDateTime], [MachineName]
		END
	ELSE
		BEGIN
			SELECT  
				[ID],
				[CompanyID],
				[UserName],
				[RevitVersion],
				[MachineName],
				[StartDateTime],
				[EndDateTime]
			FROM pal.LogSession
			WHERE ( CompanyID = @CompanyID )
			AND ( [StartDateTime] >= @Date ) 
			ORDER BY [StartDateTime], [MachineName]
		END
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogSummaries'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogSummaries' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogSummaries]
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_LogSummaries]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  
			pal.LogSummary.[ID],
			[DocSessionID],
			[CompanyID],
			[EventId],
			pal.LogSummary.[GroupCt],
			pal.LogSummary.[InPlaceCt],
			pal.LogSummary.[UnPlacedRoomCt],
			pal.LogSummary.[UnenclosedRoomCt],
			pal.LogSummary.[PlacedRoomCt],
			pal.LogSummary.[UnPlacedSpaceCt],
			pal.LogSummary.[UnenclosedSpaceCt],
			pal.LogSummary.[PlacedSpaceCt],
			pal.LogSummary.[ViewCt],
			pal.LogSummary.[PhaseCt],
			pal.LogSummary.[DesOptCt],
			pal.LogSummary.[WorksetCt],
			pal.LogSummary.[FamilyCt],
			pal.LogSummary.[InstanceCt],
			pal.LogSummary.[MaterialCt],
			pal.LogSummary.[ViewFilterCt],
			[SummaryDateTime],
			pal.LogSummary.[UnplacedFamilyCt],
			pal.LogSummary.[LevelCt],
			pal.LogSummary.[WarningCt]
		FROM pal.LogSummary
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
		WHERE ( CompanyID = @CompanyID )
		ORDER BY [SummaryDateTime], [DocSessionID]
		END
	ELSE
		BEGIN
			SELECT  
				pal.LogSummary.[ID],
				[DocSessionID],
				[CompanyID],
				[EventId],
				pal.LogSummary.[GroupCt],
				pal.LogSummary.[InPlaceCt],
				pal.LogSummary.[UnPlacedRoomCt],
				pal.LogSummary.[UnenclosedRoomCt],
				pal.LogSummary.[PlacedRoomCt],
				pal.LogSummary.[UnPlacedSpaceCt],
				pal.LogSummary.[UnenclosedSpaceCt],
				pal.LogSummary.[PlacedSpaceCt],
				pal.LogSummary.[ViewCt],
				pal.LogSummary.[PhaseCt],
				pal.LogSummary.[DesOptCt],
				pal.LogSummary.[WorksetCt],
				pal.LogSummary.[FamilyCt],
				pal.LogSummary.[InstanceCt],
				pal.LogSummary.[MaterialCt],
				pal.LogSummary.[ViewFilterCt],
				[SummaryDateTime],
				pal.LogSummary.[UnplacedFamilyCt],
				pal.LogSummary.[LevelCt],
				pal.LogSummary.[WarningCt]
			FROM pal.LogSummary
			INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			AND ( [SummaryDateTime] >= @Date ) 
			ORDER BY [SummaryDateTime], [DocSessionID]
		END
	END 
' )
	
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogViewTypes'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogViewTypes' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogViewTypes]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogViewTypes]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  
			pal.LogViewType.[ID],
			[DocSessionID],
			[ViewTypeName],
			pal.LogViewType.[ViewCt],
			[ViewDateTime]
		FROM pal.LogViewType
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
		WHERE ( CompanyID = @CompanyID )
		ORDER BY [ViewDateTime], [DocSessionID]
		END
	ELSE
		BEGIN
			SELECT  
				pal.LogViewType.[ID],
				[DocSessionID],
				[ViewTypeName],
				pal.LogViewType.[ViewCt],
				[ViewDateTime]
			FROM pal.LogViewType
			INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			AND ( [ViewDateTime] >= @Date ) 
			ORDER BY [ViewDateTime], [DocSessionID]
		END
	END 
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogWarnings'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogWarnings' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogWarnings]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogWarnings]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  
			pal.LogWarning.[ID],
			[DocSessionID],
			[Severity],
			[WarningId],
			[Description],
			[ElementId],
			[ElementName],
			[LevelName],
			[Workset],
			[WarningDateTime]
		FROM pal.LogWarning
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
		WHERE ( CompanyID = @CompanyID )
		ORDER BY [WarningDateTime], [LevelName], [Description]
		END
	ELSE
		BEGIN
			SELECT  
				pal.LogWarning.[ID],
				[DocSessionID],
				[Severity],
				[WarningId],
				[Description],
				[ElementId],
				[ElementName],
				[LevelName],
				[Workset],
				[WarningDateTime]
			FROM pal.LogWarning
			INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			AND ( [WarningDateTime] >= @Date ) 
			ORDER BY [WarningDateTime], [LevelName], [Description]
		END
	END 
' )	

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogWarningSummaries'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogWarningSummaries' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogWarningSummaries]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogWarningSummaries]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT  
			pal.LogWarningSummary.[ID],
			[DocSessionID],
			[ElementIds],
			[Description],
			[LogDateTime]

		FROM pal.LogWarningSummary
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
		WHERE ( CompanyID = @CompanyID )
		ORDER BY [LogDateTime], [Description]
		END
	ELSE
		BEGIN
			SELECT  
				pal.LogWarningSummary.[ID],
				[DocSessionID],
				[ElementIds],
				[Description],
				[LogDateTime]
			FROM pal.LogWarningSummary
			INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID )
			AND ( [LogDateTime] >= @Date ) 
			ORDER BY [LogDateTime], [Description]
		END
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_ProjectID_ByPath2'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_ProjectID_ByPath2' )
		DROP PROCEDURE  pal.[ctcsp_Get_ProjectID_ByPath2]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_ProjectID_ByPath2] 
	(
	    @ID int output,
		@CentralFilePath NVarChar(255)
	)
		AS
		BEGIN
				
			SET NOCOUNT ON;

			SET @ID=(SELECT ProjectID
			FROM asset.ProjectPath
			WHERE (CentralFilePath = @CentralFilePath) )
		END 
		
        RETURN  @ID 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_ProjectID_ByPath'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_ProjectID_ByPath' )
		DROP PROCEDURE  pal.[ctcsp_Get_ProjectID_ByPath]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_ProjectID_ByPath] 
	(
	    @ID int output,
		@CompanyID int,
		@CentralFilePath NVarChar(255)
	)
		AS
		BEGIN
				
			SET NOCOUNT ON;

			SET @ID=(SELECT TOP 1
					[asset].[ProjectPath].ProjectID
					FROM  [asset].[ProjectPath] 
					INNER JOIN  [asset].[Project] ON [asset].[ProjectPath].ProjectID = [asset].Project.ID
					WHERE [asset].[Project].CompanyID = @CompanyID
					AND [asset].[ProjectPath].CentralFilePath = @CentralFilePath)
		END 
		
        RETURN  @ID
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSession'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSession' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSession]
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Upd_LogDocSession]
	(
	    @ResultCount int output,
		@ID uniqueidentifier,
		@STCDuration float,
		@STCDateTime datetime,
		@SessionHours float,
		@PhaseCt int,
		@DesOptCt int,
		@ViewCt int,
		@GroupCt int,
		@FamilyCt int,
		@InstanceCt int,
		@UnplacedFamilyCt int,
		@InPlaceCt int,
		@UnPlacedRoomCt int,
		@UnenclosedRoomCt int,
		@PlacedRoomCt int,
		@UnPlacedSpaceCt int,
		@UnenclosedSpaceCt int,
		@PlacedSpaceCt int,
		@MaterialCt int,
		@ViewFilterCt int,
		@LevelCt int,
		@ElemAddedCt int,
		@ElemDeletedCt int,
		@ElemModifiedCt int,
		@WarningCt int,
		@HasClosed bit,
		@Status bit
	)
	AS
		SET NOCOUNT OFF;
	BEGIN TRY		
	UPDATE [pal].[LogDocSession] SET 
			[STCDuration] = @STCDuration,
			[STCDateTime] = @STCDateTime,
			[SessionHours] = @SessionHours,
			[PhaseCt] = @PhaseCt,
			[DesOptCt] = @DesOptCt,
			[ViewCt] = @ViewCt,
			[GroupCt] = @GroupCt,
			[FamilyCt] = @FamilyCt,
			[InstanceCt] = @InstanceCt,
			[UnplacedFamilyCt] = @UnplacedFamilyCt,
			[InPlaceCt] = @InPlaceCt,
			[UnPlacedRoomCt] = @UnPlacedRoomCt,
			[UnenclosedRoomCt] = @UnenclosedRoomCt,
			[PlacedRoomCt] = @PlacedRoomCt,
			[UnPlacedSpaceCt] = @UnPlacedSpaceCt,
			[UnenclosedSpaceCt] = @UnenclosedSpaceCt,
			[PlacedSpaceCt] = @PlacedSpaceCt,
			[MaterialCt] = @MaterialCt,
			[ViewFilterCt] = @ViewFilterCt,
			[LevelCt] = @LevelCt,
			[ElemAddedCt] = @ElemAddedCt,
			[ElemDeletedCt] = @ElemDeletedCt,
			[ElemModifiedCt] = @ElemModifiedCt,
			[WarningCt] = @WarningCt,
			[HasClosed] = @HasClosed,
			[Status] = @Status
		WHERE (([ID] = @ID));
		
		SET @ResultCount=@@ROWCOUNT
	END TRY
	BEGIN CATCH
		-- RETURN ERROR NUMBER.  
		-- 2627 = Violation of PRIMARY KEY constraint
		-- 547 = The INSERT statement conflicted with the FOREIGN KEY constraint 
		--(LogDocSession does not contain a record with the correct primary key)
		SET @ResultCount = (SELECT ERROR_NUMBER())
		PRINT ERROR_MESSAGE()
	END CATCH		
	RETURN @ResultCount 
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSession_ByUserAndMachineName'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSession_ByUserAndMachineName' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSession_ByUserAndMachineName]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSession_ByUserAndMachineName]
	(
	    @ResultCount int output,
		@CompanyID int,
		@UserName nvarchar(100),
		@MachineName nvarchar(255)
	)

	AS
		SET NOCOUNT OFF;
				
	UPDATE [pal].[LogDocSession] SET HasClosed = 1
		WHERE (HasClosed = 0)
		AND ( CompanyID = @CompanyID )
		AND ( UserName = @UserName )
		AND ( MachineName = @MachineName )
		AND ( LogDocSession.DocDateTime BETWEEN CAST(GETDATE() AS DATE) AND DATEADD(DAY, 1, CAST(GETDATE() AS DATE)))

		SET @ResultCount=@@ROWCOUNT
		RETURN @ResultCount 
' )
		
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSession_ByID'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSession_ByID' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSession_ByID]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSession_ByID]
	(
	    @ResultCount int output,
		@ID uniqueidentifier
	)

	AS
		SET NOCOUNT OFF;
				
	UPDATE [pal].[LogDocSession] SET HasClosed = 1
		WHERE (HasClosed = 0)
		AND ( ID = @ID )
		SET @ResultCount=@@ROWCOUNT
		RETURN @ResultCount 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllConflictingProjectIds] 
	(
		@p_CompanyID int,
		@p_UserName NVARCHAR(100)
	)
	AS
	BEGIN

		SET NOCOUNT ON;

		INSERT INTO pal.LogDocumentProjChange(
			 [DocSessionID]
			,[CentralFileName]
			,[UserName]
			,[OldProjID]
			,[NewProjID]
			,[DateCreated])
		SELECT ds.ID, ds.CentralFileName, @p_UserName, ds.ProjectID, pp.ProjectID, GETUTCDATE()
		FROM pal.LogDocSession as ds
		INNER JOIN
			asset.ProjectPath as pp
			ON ds.CentralFilePath = pp.CentralFilePath 
			AND ds.ProjectID <> pp.ProjectID 
			INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
			INNER JOIN asset.Project ON ds.ProjectID = asset.Project.ID
		WHERE (ds.CompanyID = @p_CompanyID)
		AND   (pr.CompanyID = @p_CompanyID)
		AND   (ds.ProjectID IS NOT NULL)

		SET NOCOUNT OFF;

		UPDATE ds
		SET ds.ProjectID = pp.ProjectID
		FROM pal.LogDocSession as ds
		INNER JOIN
			asset.ProjectPath as pp
			ON ds.CentralFilePath = pp.CentralFilePath 
			AND ds.ProjectID <> pp.ProjectID 
			INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
			INNER JOIN asset.Project ON ds.ProjectID = asset.Project.ID
		WHERE (ds.CompanyID = @p_CompanyID)
		AND   (pr.CompanyID = @p_CompanyID)
		AND   (ds.ProjectID IS NOT NULL)

		Return @@ROWCOUNT;

	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllDeletedProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN

		SET NOCOUNT OFF;
		UPDATE t1
		SET t1.ProjectID = t2.ProjectID
		FROM pal.LogDocSession AS t1
		LEFT JOIN asset.Project As pr ON pr.ID = t1.ProjectID 
		INNER JOIN asset.ProjectPath AS t2
		ON t1.CentralFilePath = t2.CentralFilePath
		INNER JOIN asset.Project AS t3 ON t2.ProjectID = t3.ID
		WHERE (t1.CompanyID = @p_CompanyID)
		AND   (pr.CompanyID = @p_CompanyID)
		AND (pr.ID IS NULL)
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds]
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceAllEmptyProjectIds] 
	(
		@p_CompanyID int,
		@p_UserName NVARCHAR(100)
	)
	AS
	BEGIN

		SET NOCOUNT ON;

		INSERT INTO pal.LogDocumentProjChange(
			[DocSessionID]
			,[CentralFileName]
			,[UserName]
			,[OldProjID]
			,[NewProjID]
			,[DateCreated])
		SELECT t1.ID, t1.CentralFileName, @p_UserName, t1.ProjectID, t2.ProjectID, GETUTCDATE()
		FROM pal.LogDocSession AS t1
				INNER JOIN asset.ProjectPath AS t2
				ON t1.CentralFilePath = t2.CentralFilePath
				WHERE (t1.CompanyID = @p_CompanyID)
				AND (t1.ProjectID IS NULL)

		SET NOCOUNT OFF;

		UPDATE t1
				SET t1.ProjectID = t2.ProjectID
				FROM pal.LogDocSession AS t1
				INNER JOIN asset.ProjectPath AS t2
				ON t1.CentralFilePath = t2.CentralFilePath
				WHERE (t1.CompanyID = @p_CompanyID)
				AND (t1.ProjectID IS NULL)

		Return @@ROWCOUNT;
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectIdsByFilePath] 
	(
		@p_CompanyID int,
		@ProjectID int,
		@UserName NVARCHAR(100), 
		@Path NVARCHAR(255)
	) 
	AS
	BEGIN

		SET NOCOUNT ON;

		INSERT INTO pal.LogDocumentProjChange(
			[DocSessionID]
			,[CentralFileName]
			,[UserName]
			,[OldProjID]
			,[NewProjID]
			,[DateCreated])
		SELECT t1.ID, t1.CentralFileName, @UserName, t1.ProjectID, @ProjectID, GETUTCDATE()
		FROM pal.LogDocSession AS t1
		WHERE (t1.CompanyID = @p_CompanyID)
		AND t1.CentralFilePath = @Path;

		SET NOCOUNT OFF;

		UPDATE pal.LogDocSession
		SET ProjectID = @ProjectID
		WHERE (pal.LogDocSession.CompanyID = @p_CompanyID)
		AND pal.LogDocSession.CentralFilePath = @Path;

		Return @@ROWCOUNT;
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessionsAndProjectFile_ReplaceProjectIdsByFilePath] 
	(
		@p_CompanyID int,
		@ProjectID int,
		@UserName NVARCHAR(100), 
		@Path NVARCHAR(255)
	)
	AS
	BEGIN

		SET NOCOUNT ON;

		INSERT INTO pal.LogDocumentProjChange(
			[DocSessionID]
			,[CentralFileName]
			,[UserName]
			,[OldProjID]
			,[NewProjID]
			,[DateCreated])
		SELECT t1.ID, t1.CentralFileName, @UserName, t1.ProjectID, @ProjectID, GETUTCDATE()
		FROM pal.LogDocSession AS t1
		WHERE (t1.CompanyID = @p_CompanyID)
		AND t1.CentralFilePath = @Path;

		SET NOCOUNT OFF;

		UPDATE pal.LogDocSession
		SET ProjectID = @ProjectID
		WHERE (CompanyID = @p_CompanyID)
		AND CentralFilePath = @Path;

		-- TODO: Add CompanyID
		UPDATE snapshot.ProjectFile
		SET ProjectID = @ProjectID
		WHERE (CompanyID = @p_CompanyID)
		AND LEFT(snapshot.ProjectFile.CentralOrSingleUserProjectFileName,LEN(snapshot.ProjectFile.CentralOrSingleUserProjectFileName) - charindex(''\'',reverse(snapshot.ProjectFile.CentralOrSingleUserProjectFileName),1)) = @Path COLLATE SQL_Latin1_General_CP1_CI_AS;

		SET NOCOUNT ON;

		Return @@ROWCOUNT;
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessionsWithConflictingProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithConflictingProjectIds' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogDocSessionsWithConflictingProjectIds]
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithConflictingProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		SELECT  s.ID AS [GUID], 
				s.CentralFileName, 
				s.ShortFileName, 
				s.ProjectID AS DocProjectID, 
				asset.Project.ProjectNumber AS DocProjectNumber, 
				pp.ProjectID AS ProjProjectID, 
				pr.ProjectNumber AS ProjProjectNumber, 
				s.DocDateTime, 
				pp.AddedDate AS ProjDateTime 
		FROM    pal.LogDocSession AS s
			INNER JOIN asset.ProjectPath AS pp
				ON	s.CentralFilePath = pp.CentralFilePath 
					AND s.ProjectID <> pp.ProjectID 
					INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
					INNER JOIN asset.Project ON s.ProjectID = asset.Project.ID
		WHERE   (s.CompanyID = @p_CompanyID)
		AND     (pr.CompanyID = @p_CompanyID)
		ORDER BY s.CentralFileName, s.ProjectID, s.DocDateTime, pp.AddedDate
			
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessionsWithDeletedProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithDeletedProjectIds' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogDocSessionsWithDeletedProjectIds]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithDeletedProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN
	SET NOCOUNT ON;
			
		SELECT 
			s.ID AS [GUID],
			s.CentralFileName, 
			s.ShortFileName,
			s.ProjectID AS DocProjectID,
			''deleted'' AS DocProjectNumber,
			pp.ProjectID AS ProjProjectID, 
			pr.ProjectNumber AS ProjProjectNumber,
			s.DocDateTime,
			pp.AddedDate AS ProjDateTime
		FROM pal.LogDocSession AS s
		LEFT JOIN asset.Project As p ON p.ID = s.ProjectID 
		INNER JOIN asset.ProjectPath As pp 
			ON s.CentralFilePath  = pp.CentralFilePath
		INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
		WHERE   (s.CompanyID = @p_CompanyID) 
		AND     (pr.CompanyID = @p_CompanyID)
		AND		(p.ID IS NULL)
		ORDER BY CentralFileName, DocProjectID, DocDateTime, ProjDateTime
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessionsWithEmptyProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithEmptyProjectIds' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogDocSessionsWithEmptyProjectIds]
	EXEC('CREATE  PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithEmptyProjectIds] 
	(
		@p_CompanyID int
	)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		SELECT  
			s.ID AS [GUID],       
			s.CentralFileName, 
			s.ShortFileName, 
			0 AS DocProjectID, 
			pr.ProjectNumber AS DocProjectNumber, 
			pp.ProjectID AS ProjProjectID, 
			pr.ProjectNumber AS ProjProjectNumber, 
			s.DocDateTime,
			pp.AddedDate AS ProjDateTime 
		FROM pal.LogDocSession AS s
			INNER JOIN
				asset.ProjectPath As pp ON 
				s.CentralFilePath = pp.CentralFilePath
				AND s.ProjectID is null
				INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
		WHERE (s.CompanyID = @p_CompanyID) 
		AND   (s.ProjectID IS NULL)
		ORDER BY CentralFileName, DocProjectID, DocDateTime, ProjDateTime
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogDocSessionsWithUnmatchedProjectIds] 
	(
		@p_CompanyID int
	)	
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;

		SELECT        
			s.ID AS [GUID],
			s.CentralFileName,
			s.ShortFileName, 
			s.ProjectID AS DocProjectID, 
			asset.Project.ProjectNumber AS DocProjectNumber, 
			pp.ProjectID AS ProjProjectID, 
			pr.ProjectNumber AS ProjProjectNumber, 
			s.DocDateTime,
			pp.AddedDate AS ProjDateTime
		FROM pal.LogDocSession As s
			INNER JOIN
				asset.ProjectPath As pp
				ON s.CentralFilePath = pp.CentralFilePath 
				AND s.ProjectID <> pp.ProjectID 
			INNER JOIN asset.Project AS pr ON pp.ProjectID = pr.ID 
			INNER JOIN asset.Project ON s.ProjectID = asset.Project.ID
		WHERE (s.CompanyID = @p_CompanyID) 
		AND   (pr.CompanyID = @p_CompanyID)
		AND (s.ProjectID IS NOT NULL)
		ORDER BY CentralFileName, DocProjectID, DocDateTime, ProjDateTime

	END
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSessions_ReplaceProjectId'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSessions_ReplaceProjectId' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSessions_ReplaceProjectId]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSessions_ReplaceProjectId] 
	(
		@p_ID uniqueidentifier
		,@p_ProjectID int
	)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.

		-- Specify in which table the row exists to update
		UPDATE pal.LogDocSession
			
		-- Specify which parameter value goes into which fields
		SET ProjectID = @p_ProjectID
			
		-- Specify how to find which record to update
		WHERE ID = @p_ID

	END 
' )
-----------------------------------------------------------------------------------------------------------
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_AddIns'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_AddIns' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_AddIns]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_AddIns]
(
	@CompanyID int,
	@Date DateTime
)
	AS
	BEGIN
			
		SET NOCOUNT ON;
		SET NOCOUNT ON;
		SELECT lastByID.DocDateTime AS LogDateTime, 
			   lastByID.MachineName,
			   la.Name, 
			   CAST(MAX(CAST(lastByID.ID AS BINARY(16))) AS UNIQUEIDENTIFIER) As DocSessionID, 
			   CAST(MAX(CAST(la.ID AS BINARY(16))) AS UNIQUEIDENTIFIER) AS ID
		FROM
		(
			SELECT MachineName, max(DocDateTime) as DocDateTime
			FROM pal.LogDocSession
			GROUP BY MachineName
		) lastByDate

		INNER JOIN pal.LogDocSession lastByID ON lastByID.MachineName = lastByDate.MachineName AND lastByID.DocDateTime = lastByDate.DocDateTime
		INNER JOIN pal.LogAddIn la ON lastByID.ID = DocSessionID

		WHERE (lastByID.CompanyID = 1 ) 
		AND (lastByID.DocDateTime >= @Date )
		AND (lastByID.RevitVersion = RevitVersion )

		GROUP BY lastByID.MachineName, lastByID.DocDateTime, la.Name
		ORDER BY lastByID.MachineName, la.Name
	END 
' )
		
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogDocSessions'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogDocSessions' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogDocSessions]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogDocSessions]
(
	@CompanyID int,
	@Date DateTime
)
	AS
	BEGIN
			
		SET NOCOUNT ON;
		
		SELECT  
				Data.ID,  
				Data.ProjectID,  
				Data.CompanyID,  
				asset.Project.ProjectNumber,  
				asset.Project.ProjectName,  
				asset.Project.ClientName,  
				UserName,  
				[Server],  
				CentralFileName,
				CentralFilePath,  
				ShortFileName,  
				LocalFileName,  
				LocalFileSize,  
				RevitVersion,  
				IsAudit,  
				DocDateTime,  
				STCDateTime,  
				LoadTime,  
				STCDuration,  
				SessionHours,  
				GroupCt,  
				InPlaceCt,  
				UnPlacedRoomCt,  
				UnenclosedRoomCt,  
				PlacedRoomCt,  
				UnPlacedSpaceCt,  
				UnenclosedSpaceCt,  
				PlacedSpaceCt,  
				ViewCt,  
				PhaseCt,  
				DesOptCt,  
				WorksetCt,  
				Data.WorksetEditCt,  
				WorksetOpenCt,  
				FamilyCt,  
				InstanceCt,  
				UnplacedFamilyCt,  
				MaterialCt,  
				ViewFilterCt,  
				LevelCt,  
				ElemAddedCt,  
				ElemDeletedCt,  
				ElemModifiedCt,  
				WarningCt,  
				MachineName,  
				BasePoint,  
				SurveyPoint,  
				AngleToTrueNorth,  
				SiteLatLong,  
				HasClosed,
				Data.[Status]
			FROM (pal.LogDocSession AS Data INNER JOIN asset.Project ON ProjectID = asset.Project.ID)  
			WHERE ([DocDateTime] =  
			(SELECT MAX([DocDateTime]) AS Expr1  
				FROM pal.LogDocSession AS LogDocSession_1  
					WHERE ([CentralFileName] = Data.[CentralFileName])  
					AND (STCDuration > 0)) 
				AND (Data.CompanyID = @CompanyID ) 
				AND (Data.DocDateTime >= @Date ))
		ORDER BY Data.DocDateTime ASC
		 
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogEvents'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogEvents' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogEvents]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogEvents]
(
	@CompanyID int,
	@Date DateTime,
	@EventName NVARCHAR(25)
)
	AS
	BEGIN
			
		SET NOCOUNT ON;
	SELECT
		pal.LogEvent.ID,
		pal.LogEvent.DocSessionID,
		pal.LogEvent.EventId,
		pal.LogEvent.EventType,
		pal.LogEvent.EventName,
		pal.LogEvent.ViewName,
		pal.LogEvent.OpenViewCt,
		pal.LogEvent.EventDateTime,
		pal.LogEvent.EventDuration,
		pal.LogEvent.ActionCt,
		pal.LogEvent.ActiveWorksetName,
		pal.LogEvent.FamilyWorksetEditCt,
		pal.LogEvent.FamilyWorksetOpenCt,
		pal.LogEvent.StandardWorksetEditCt,
		pal.LogEvent.StandardWorksetOpenCt,
		pal.LogEvent.UserWorksetEditCt,
		pal.LogEvent.UserWorksetOpenCt,
		pal.LogEvent.ViewWorksetEditCt,
		pal.LogEvent.ViewWorksetOpenCt
		FROM pal.LogDocSession AS Data
		INNER JOIN pal.LogEvent ON Data.ID = pal.LogEvent.DocSessionID 
		WHERE ([DocDateTime] = (SELECT MAX([DocDateTime]) AS Expr1
			FROM  pal.LogDocSession AS LogDocSession_1
			WHERE ([CentralFileName] = Data.[CentralFileName])
				AND (ProjectID = Data.ProjectID)
				AND (pal.LogEvent.EventName = @EventName )
				AND (STCDuration > 0)))
		AND (Data.CompanyID = @CompanyID ) 
		AND (Data.DocDateTime >= @Date )
		ORDER BY Data.DocDateTime ASC
		 
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogEventsShort'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogEventsShort' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogEventsShort]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogEventsShort]
(
	@CompanyID int,
	@Date DateTime,
	@EventName NVARCHAR(25)
)
	AS
	BEGIN
			
		SET NOCOUNT ON;
	SELECT
		pal.LogEvent.ID,
		pal.LogEvent.DocSessionID,
		pal.LogEvent.EventName,
		pal.LogEvent.ViewName,
		pal.LogEvent.ActionCt,
		pal.LogEvent.EventDateTime,
		pal.LogEvent.EventDuration
		FROM pal.LogDocSession AS Data
		INNER JOIN pal.LogEvent ON Data.ID = pal.LogEvent.DocSessionID 
		WHERE ([DocDateTime] = (SELECT MAX([DocDateTime]) AS Expr1
			FROM  pal.LogDocSession AS LogDocSession_1
			WHERE ([CentralFileName] = Data.[CentralFileName])
				AND (ProjectID = Data.ProjectID)
				AND (pal.LogEvent.EventName = @EventName )
				AND (STCDuration > 0)))
		AND (Data.CompanyID = @CompanyID ) 
		AND (Data.DocDateTime >= @Date )
		ORDER BY Data.DocDateTime ASC

		
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogLinks'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogLinks' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogLinks]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogLinks]
(
	@CompanyID int,
	@Date DateTime
)
	AS
	BEGIN
			
		SET NOCOUNT ON;

	SELECT
		pal.LogLink.ID,
		pal.LogLink.DocSessionID,
		ProjectID,
		CentralFileName,
		ShortFileName,
		pal.LogLink.LinkPath,
		pal.LogLink.LinkShortFileName,
		pal.LogLink.LinkType,
		pal.LogLink.LinkStatus,
		pal.LogLink.UserName,
		pal.LogLink.LinksDateTime
	FROM pal.LogDocSession AS Data
	INNER JOIN pal.LogLink ON Data.ID = pal.LogLink.DocSessionID 
	WHERE ([DocDateTime] = (SELECT MAX([DocDateTime]) AS Expr1
	FROM  pal.LogDocSession AS LogDocSession_1
	WHERE ([CentralFileName] = Data.[CentralFileName])
	AND (ProjectID = Data.ProjectID)
	AND (STCDuration > 0)))
		AND (Data.CompanyID = @CompanyID ) 
		AND (Data.DocDateTime >= @Date )
		ORDER BY Data.DocDateTime ASC

		
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogMachines'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogMachines' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogMachines]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogMachines]
(
	@CompanyID int,
	@Date DateTime
)
	AS
	BEGIN
			
		SET NOCOUNT ON;

	SELECT
		pal.LogMachine.ID,
		DocSessionID,
		pal.LogMachine.MachineName,
		ProcessorId,
		IPAddress,
		OperatingSystem,
		CPU,
		Motherboard,
		Bios,
		RAM,
		RAM_Slots,
		Video,
		HDD,
		MAC,
		LogDateTime 
		FROM  pal.LogDocSession AS Data 
		INNER JOIN pal.LogMachine ON Data.ID = pal.LogMachine.DocSessionID 
		WHERE(DocDateTime = 
		(SELECT MAX(DocDateTime) AS Expr1 
		FROM  pal.LogDocSession AS LogDocSession_1 
		WHERE(MachineName = Data.MachineName))) 

		AND (Data.CompanyID = @CompanyID ) 
		AND (Data.DocDateTime >= @Date )
		ORDER BY Data.DocDateTime ASC

	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogSessions'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogSessions' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogSessions]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogSessions]
(
	@CompanyID int,
	@StartDate DateTime,
	@EndDate DateTime
)
	AS
	BEGIN
			
		SET NOCOUNT ON;

	SELECT
		 [ID],
		 [CompanyID],
		 [UserName],
		 [MachineName],
		 [RevitVersion],
		 [StartDateTime],
		 [EndDateTime] 
		 FROM [pal].[LogSession] 

	WHERE (StartDateTime <= @EndDate) 
	AND ((EndDateTime >= @StartDate) 
	OR (EndDateTime IS NULL) ) 
	AND (CompanyID = @CompanyID ) 
	ORDER BY MachineName ASC

	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogViewTypes'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogViewTypes' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogViewTypes]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogViewTypes]
(
	@CompanyID int,
	@Date DateTime
)
	AS
	BEGIN
			
		SET NOCOUNT ON;

	SELECT
		pal.LogViewType.ID,
		pal.LogViewType.DocSessionID,
		ProjectID,
		CentralFileName,
		ShortFileName, 
		pal.LogViewType.ViewTypeName, 
		pal.LogViewType.ViewCt,
		pal.LogViewType.ViewDateTime 
		FROM pal.LogDocSession AS Data
		INNER JOIN pal.LogViewType ON Data.ID = pal.LogViewType.DocSessionID
		WHERE ([DocDateTime] =
		(SELECT MAX([DocDateTime]) AS Expr1 
		FROM pal.LogDocSession AS LogDocSession_1 
		WHERE ([CentralFileName] = Data.[CentralFileName]) 
		AND (ProjectID = Data.ProjectID)  
		AND (STCDuration > 0)  ))

	AND (Data.CompanyID = @CompanyID ) 
	AND (Data.DocDateTime >= @Date )

	ORDER BY Data.CentralFileName, pal.LogViewType.ViewTypeName

	END 
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogWarnings'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogWarnings' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogWarnings]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogWarnings]
(
	@CompanyID int,
	@Date DateTime
)
	AS
	BEGIN
			
		SET NOCOUNT ON;

	SELECT
		pal.LogWarning.ID, 
		pal.LogWarning.DocSessionID, 
		ProjectID, 
		CentralFileName, 
		ShortFileName, 
		pal.LogWarning.WarningDateTime, 
		pal.LogWarning.WarningId, 
		pal.LogWarning.Severity, 
		pal.LogWarning.Description, 
		pal.LogWarning.ElementId, 
		pal.LogWarning.ElementName, 
		pal.LogWarning.LevelName, 
		pal.LogWarning.Workset 
	FROM pal.LogDocSession AS Data 
	INNER JOIN pal.LogWarning ON Data.ID = pal.LogWarning.DocSessionID 
	WHERE ([DocDateTime] = 
		(SELECT MAX([DocDateTime]) AS Expr1 
			FROM pal.LogDocSession AS LogDocSession_1 
				WHERE ([CentralFileName] = Data.[CentralFileName]) 
				AND (ProjectID = Data.ProjectID) 
				AND (STCDuration > 0) ))
	AND (Data.CompanyID = @CompanyID ) 
	AND (Data.DocDateTime >= @Date )

	ORDER BY Data.CentralFileName, pal.LogWarning.WarningId

	END 
' )
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogWarningSummaries'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogWarningSummaries' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogWarningSummaries]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogWarningSummaries]
(
	@CompanyID int,
	@Date DateTime
)
	AS
	BEGIN
			
		SET NOCOUNT ON;

	SELECT
		pal.LogWarningSummary.ID, 
        pal.LogWarningSummary.DocSessionID, 
        pal.LogWarningSummary.ElementIds, 
        pal.LogWarningSummary.Description, 
        pal.LogWarningSummary.LogDateTime 

    FROM pal.LogDocSession AS Data 
    INNER JOIN pal.LogWarningSummary ON Data.ID = pal.LogWarningSummary.DocSessionID 
    WHERE ([DocDateTime] = 
        (SELECT MAX([DocDateTime]) AS Expr1 
            FROM pal.LogDocSession AS LogDocSession_1 
                WHERE ([CentralFileName] = Data.[CentralFileName]) 
                AND (ProjectID = Data.ProjectID) 
                AND (STCDuration > 0) ))
	AND (Data.CompanyID = @CompanyID ) 
	AND (Data.DocDateTime >= @Date )

	ORDER BY Data.CentralFileName, pal.LogWarningSummary.Description

	END 
' )
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_LogCrashes'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_LogCrashes' )
		DROP PROCEDURE  pal.[ctcsp_Get_LogCrashes]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_LogCrashes]
(
	@CompanyID int, 
	@Date datetime
)
	AS
	BEGIN
			
	SET NOCOUNT ON;

	IF @Date IS NULL
		BEGIN
		SELECT
			pal.LogCrash.[ID],
			pal.LogCrash.[DocSessionID],
			pal.LogCrash.[UserName],
			pal.LogCrash.[CentralFileName],
			pal.LogCrash.[LocalFileName],
			pal.LogCrash.[RevitVersion],
			pal.LogCrash.[LocalFileSize],
			[Description],
			[ExceptionDateTime],
			[LogDateTime]
		FROM pal.LogCrash 
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
		WHERE ( CompanyID = @CompanyID ) 
		ORDER BY [LogDateTime], [UserName]
		END
	ELSE
		BEGIN
			SELECT
			pal.LogCrash.[ID],
			pal.LogCrash.[DocSessionID],
			pal.LogCrash.[UserName],
			pal.LogCrash.[CentralFileName],
			pal.LogCrash.[LocalFileName],
			pal.LogCrash.[RevitVersion],
			pal.LogCrash.[LocalFileSize],
			[Description],
			[ExceptionDateTime],
			[LogDateTime]
		FROM pal.LogCrash 
		INNER JOIN pal.LogDocSession as d ON d.ID = DocSessionID 
			WHERE ( CompanyID = @CompanyID ) 
			AND ( [LogDateTime] >= @Date ) 
			ORDER BY [LogDateTime], [UserName] 
		END
	END 
' )
	
	
PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Last_LogDocSessionsShort'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Last_LogDocSessionsShort' )
		DROP PROCEDURE  pal.[ctcsp_Get_Last_LogDocSessionsShort]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Last_LogDocSessionsShort]
(
	@CompanyID int,
	@Date DateTime
)
	AS
	BEGIN
			
		SET NOCOUNT ON;
		
		SELECT  
				Data.ID,  
				Data.ProjectID,  
				Data.CompanyID,
				UserName, 
				CentralFileName,  
				ShortFileName, 
				LocalFileSize,
				DocDateTime,  
				STCDateTime,
				HasClosed  
			FROM (pal.LogDocSession AS Data INNER JOIN asset.Project ON ProjectID = asset.Project.ID)  
			WHERE ([DocDateTime] =  
			(SELECT MAX([DocDateTime]) AS Expr1  
				FROM pal.LogDocSession AS LogDocSession_1  
					WHERE ([CentralFileName] = Data.[CentralFileName])  
					AND (STCDuration > 0)) 
				AND (Data.CompanyID = @CompanyID ) 
				AND (Data.DocDateTime >= @Date ))
		ORDER BY Data.DocDateTime ASC

		 
	END 
' )

PRINT 'PAL - Updating stored procedure for dbo schema ctcsp_Get_Sessions_ByNamedDateRange'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Sessions_ByNamedDateRange' )
		DROP PROCEDURE  dbo.[ctcsp_Get_Sessions_ByNamedDateRange]
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Sessions_ByNamedDateRange]
		@p_NamedDateRange nvarchar(7)
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
			
		DECLARE @sql varchar(1900)
		DECLARE @where varchar(1000)

		SET @sql = 
			''SELECT        
				LogDocSession.ID As Id, 
				ProjectID as projectId, 
				Project.ProjectNumber AS [Project Number], 
				Project.ProjectName AS [Project Name], 
				Project.ClientName AS [Client Name], 
				UserName AS Contributor, 
				Server, 
				CentralFileName AS [Central File], 
				ShortFileName AS [File Name], 
				LocalFileName AS [Local File], 
				LocalFileSize / 1048576.0 AS [File Size (MB)], 
				RevitVersion AS [Revit Version], 
				IsAudit AS Auditing, 
				DocDateTime AS Opened, 
				STCDateTime AS [Last Saved], 
				LoadTime AS [Open Duration (Sec)], 
				STCDuration AS [STC Duration (Sec)], 
				SessionHours AS [Session Hours], 
				GroupCt AS Groups, 
				InPlaceCt AS [In-place Families], 
				UnPlacedRoomCt AS [Unplaced Rooms], 
				UnenclosedRoomCt AS [Unenclosed Rooms], 
				PlacedRoomCt AS Rooms, 
				UnPlacedSpaceCt AS [Unplaced Spaces], 
				UnenclosedSpaceCt AS [Unenclosed Spaces], 
				PlacedSpaceCt AS Spaces,
				ViewCt AS Views, 
				PhaseCt AS Phases, 
				DesOptCt AS [Design Options], 
				WorksetCt AS Worksets, 
				WorksetEditCt AS EditableWorksets,
				WorksetOpenCt AS OpenWorksets, 
				FamilyCt AS Families, 
				InstanceCt AS [Family Instances], 
				UnplacedFamilyCt AS [Unplaced Families],
				MaterialCt AS Materials, 
				ViewFilterCt AS [View Filters], 
				LevelCt AS Levels, ElemAddedCt AS Added, 
				ElemDeletedCt AS Deleted, 
				ElemModifiedCt AS Modified, 
				ElemAddedCt + ElemDeletedCt + 
				ElemModifiedCt AS [Edited Items], 
				WarningCt AS Warnings,
				HasClosed As [Session Closed], 
				MachineName,
				BasePoint,
				SurveyPoint,
				AngleToTrueNorth,
				CONVERT(DateTime,CONVERT(Date, DocDateTime, 101)) AS DayOpened
			
				FROM pal.LogDocSession INNER JOIN asset.Project ON ProjectID = asset.Project.ID ''
				
			SET @where = [pal].[ctcfn_GetNamedDateRangeWhereClause](@p_NamedDateRange, ''DocDateTime'');
			EXEC(@sql + @where + '' AND (ProjectID IS NOT NULL) AND (STCDuration > 0);'');
	END ');

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Current_AddIns'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Current_AddIns' )
		DROP PROCEDURE  dbo.[ctcsp_Get_Current_AddIns]
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Current_AddIns]
	
	AS
	BEGIN
		-- SET NOCOUNT ON is added to prevent extra result sets from
		-- interfering with SELECT statements.
		SET NOCOUNT ON;
		SELECT lastByID.DocDateTime AS LogDateTime, 
			   lastByID.MachineName,
			   la.Name, 
			   CAST(MAX(CAST(lastByID.ID AS BINARY(16))) AS UNIQUEIDENTIFIER) As DocSessionID, 
			   CAST(MAX(CAST(la.ID AS BINARY(16))) AS UNIQUEIDENTIFIER) AS ID
		FROM
		(
			SELECT MachineName, max(DocDateTime) as DocDateTime
			FROM pal.LogDocSession
			GROUP BY MachineName
		) lastByDate

		INNER JOIN pal.LogDocSession lastByID ON lastByID.MachineName = lastByDate.MachineName AND lastByID.DocDateTime = lastByDate.DocDateTime
		INNER JOIN pal.LogAddIn la ON lastByID.ID = DocSessionID

		WHERE (lastByID.CompanyID = 1 ) 
		
		AND (lastByID.RevitVersion = RevitVersion )

		GROUP BY lastByID.MachineName, lastByID.DocDateTime, la.Name
		ORDER BY lastByID.MachineName, la.Name
	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_Projects_InUseByDate'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Projects_InUseByDate' )
		DROP PROCEDURE  pal.[ctcsp_Get_Projects_InUseByDate]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Get_Projects_InUseByDate] 
	(
		@CompanyID int,
		@Date DateTime
	)		
	AS
	BEGIN
		

		SET NOCOUNT ON;

		SELECT 
			ID,
			CompanyID,
			ProjectNumber,
			Office,
			ProjectName,
			BuildingName,
			ClientName, 
			StreetAddress,
			StreetAddress2,
			StreetAddress3,
			ProjectPhase,
			ProjectIssueDate, 
			Author, 
			City,
			StateOrProvince,
			PostalCode,
			CountryName,
			OrgName,
			OrgDescription,
			ProjectImage,
			AddedDate,
			UpdatedDate,
			AddedByUserID,
			UpdatedByUserID, 
			[Status]
		FROM asset.Project
		WHERE (CompanyID = @CompanyID ) 
		AND ID  in (
			SELECT asset.Project.ID FROM  asset.Project 
			INNER JOIN pal.LogDocSession ON asset.Project.ID = pal.LogDocSession.ProjectID
			WHERE pal.LogDocSession.DocDateTime >= @Date )
	
		ORDER BY [ProjectNumber]

	END 
' )

PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Get_ProjectsFull_InUse'
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_ProjectsFull_InUse' )
		DROP PROCEDURE  dbo.[ctcsp_Get_ProjectsFull_InUse]
	EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_ProjectsFull_InUse] 
	
	AS
	BEGIN
			
		SET NOCOUNT ON;

		SELECT 
				[Id]
				,[Project]
				,[Project Number]
				,[Project Name]
				,[Client Name]
				,[Issue Date]
				,[Days Until Issue]
				,[Office]
				,[BuildingName]
				,[ClientName]
				,[StreetAddress]
				,[StreetAddress2]
				,[StreetAddress3]
				,[ProjectPhase]
				,[Author]
				,[City]
				,[StateOrProvince]
				,[PostalCode]
				,[CountryName]
				,[OrgName]
				,[OrgDescription]
				,AddedDate
		FROM pal.ctcvw_Projects 
		where  Id  in (SELECT asset.Project.ID FROM  asset.Project INNER JOIN pal.LogDocSession ON asset.Project.ID = pal.LogDocSession.ProjectID)

		ORDER BY [Project Number]
		

		END 
	
		' )
		
		PRINT 'PAL - Updating view for dbo schema dbo.LogMachines'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'LogMachines' )
		DROP VIEW  dbo.LogMachines

		EXEC('CREATE VIEW [dbo].[LogMachines]
					AS
					SELECT  pal.LogMachine.ID AS Id, 
							pal.LogDocSession.ID AS DocSessionId, 
							pal.LogMachine.ProcessorId, 
							pal.LogMachine.MachineName, 
							pal.LogMachine.MAC, 
							pal.LogMachine.OperatingSystem, 
							pal.LogMachine.HDD, 
							pal.LogMachine.Motherboard, 
							pal.LogMachine.Bios, 
							pal.LogMachine.RAM, 
							pal.LogMachine.RAM_Slots, 
							pal.LogMachine.CPU, 
							pal.LogMachine.Video, 
							pal.LogMachine.LogDateTime, 
							pal.LogMachine.IPAddress
					FROM pal.LogMachine 
					INNER JOIN pal.LogDocSession ON pal.LogMachine.DocSessionID = pal.LogDocSession.ID
				')
		PRINT ' end creating LogMachines '

	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSession_ByGUID'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSession_ByGUID' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSession_ByGUID]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSession_ByGUID]
	(
	    @ResultCount int output,
		@ID uniqueidentifier
	)

	AS
		SET NOCOUNT OFF;
				
	UPDATE [pal].[LogDocSession] SET HasClosed = 1
		WHERE (HasClosed = 0)
		AND ( ID = @ID )
		SET @ResultCount=@@ROWCOUNT
		RETURN @ResultCount 
	' )
	
	PRINT 'PAL - Updating stored procedure for pal schema ctcsp_Upd_LogDocSession_GUID'
	IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Upd_LogDocSession_GUID' )
		DROP PROCEDURE  pal.[ctcsp_Upd_LogDocSession_GUID]
	EXEC('CREATE PROCEDURE [pal].[ctcsp_Upd_LogDocSession_GUID]
	(
	    @ResultCount int output,
		@ID uniqueidentifier
	)

	AS
		SET NOCOUNT OFF;
				
	UPDATE [pal].[LogDocSession] SET HasClosed = 1
		WHERE (HasClosed = 0)
		AND ( ID = @ID )
		SET @ResultCount=@@ROWCOUNT
		RETURN @ResultCount 
	' )

		PRINT 'PAL - Updating view for dbo schema ctcsp_Get_Session_Machines_ByNamedDateRange'
		IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ctcsp_Get_Session_Machines_ByNamedDateRange' )
		DROP PROCEDURE  dbo.ctcsp_Get_Session_Machines_ByNamedDateRange

		EXEC('CREATE PROCEDURE [dbo].[ctcsp_Get_Session_Machines_ByNamedDateRange]
			@p_NamedDateRange nvarchar(7)
		AS
		BEGIN

			SET NOCOUNT ON;
				
			DECLARE @sql varchar(1000)
			DECLARE @and varchar(1000)

			SET @sql = 
				''SELECT        
					dbo.LogMachines.DocSessionId, 
					dbo.LogMachines.MachineName, 
					dbo.LogMachines.IPAddress, 
					dbo.LogMachines.OperatingSystem, 
					dbo.LogMachines.CPU, 
					dbo.LogMachines.RAM, 
					dbo.LogMachines.RAM_Slots, 
					dbo.LogMachines.Video, 
					dbo.LogMachines.HDD, 
					dbo.LogMachines.MAC, 
					dbo.LogMachines.LogDateTime AS [Date Created]
				FROM pal.LogDocSession 
				INNER JOIN dbo.LogMachines ON pal.LogDocSession.ID = dbo.LogMachines.DocSessionId
				WHERE ((pal.LogDocSession.ProjectID IS NOT NULL)
				AND (STCDuration > 0)) ''

			SET @and = [pal].[ctcfn_GetNamedDateRangeANDClause](@p_NamedDateRange, ''[DocDateTime]'');	
				
			EXEC(@sql + @and + '' ORDER BY [Date Created]'');

		END ');
	
		UPDATE t1
		SET t1.MachineName = t2.MachineName
		FROM pal.LogDocSession AS t1
		INNER JOIN pal.LogMachine AS t2
		ON t1.ID = t2.DocSessionID
		WHERE (t1.MachineName IS NULL)

	END

	-- By this time all upgrading has been do to version 5, so set those flags.
	SET @palvers = 5	

	-- Update Schema Version to the latest version
	UPDATE  [asset].SchemaData
	SET     [CurrentActivitySchemaVersion] = @palvers,
			[CurrentSnapshotSchemaVersion] = @snapvers
			
	PRINT 'Committing the transaction...'
	
    COMMIT TRANSACTION;

	PRINT 'Process complete!';	
	
END TRY

BEGIN CATCH
    IF XACT_STATE() <> 0 
	BEGIN 
		PRINT 'ERROR DETECTED.  Rolling back the changes.'
		ROLLBACK TRANSACTION;
		PRINT 'Rollback is complete.'
	END
    PRINT 'Error Message:  ' + ERROR_MESSAGE();
END CATCH;

---------------------------------------------------------------------------
---- Summary: Rebuild diagram [Diagram_All]
---------------------------------------------------------------------------
print '=== Restoring diagram [Diagram_All] ===';
set nocount on;
declare @id int;
declare @outputs table (Id int not null);
begin try
  if exists (select [name] from dbo.sysdiagrams where [name] = 'Diagram_All')
  begin
      set @id = (select top(1) diagram_id from dbo.sysdiagrams where [name] = 'Diagram_All' order by diagram_id);
      update dbo.sysdiagrams set [principal_id] = 1, [version] = 1, [definition] = 0x where diagram_id = @id;
  end
  else
  begin
      insert into dbo.sysdiagrams ([name], [principal_id], [version], [definition]) output inserted.diagram_id into @outputs values ('Diagram_All', 1, 1, 0x);
      set @id = (select top(1) Id from @outputs order by Id);
  end
end try
begin catch
    print '=== ' + error_message() + ' ===';
    return;
end catch;
 
begin try
 UPDATE sysdiagrams SET [definition] .Write ( 0xD0CF11E0A1B11AE1000000000000000000000000000000003E000300FEFF0900, null, 0) WHERE diagram_id = @id -- index:1
    UPDATE sysdiagrams SET [definition] .Write ( 0x0600000000000000000000000200000001000000000000000010000063000000, null, 0) WHERE diagram_id = @id -- index:33
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000000FEFFFFFF000000000000000066000000FFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:65
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:97
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:129
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:161
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:193
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:225
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:257
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:289
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:321
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:353
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:385
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:417
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:449
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:481
    UPDATE sysdiagrams SET [definition] .Write ( 0xFDFFFFFF65000000030000000400000005000000060000000700000008000000, null, 0) WHERE diagram_id = @id -- index:513
    UPDATE sysdiagrams SET [definition] .Write ( 0x090000000A0000000B0000000C0000000D0000000E0000000F00000010000000, null, 0) WHERE diagram_id = @id -- index:545
    UPDATE sysdiagrams SET [definition] .Write ( 0x1100000012000000130000001400000015000000160000001700000018000000, null, 0) WHERE diagram_id = @id -- index:577
    UPDATE sysdiagrams SET [definition] .Write ( 0x19000000FEFFFFFF1B0000001C0000001D0000001E0000001F00000020000000, null, 0) WHERE diagram_id = @id -- index:609
    UPDATE sysdiagrams SET [definition] .Write ( 0x2100000022000000230000002400000025000000260000002700000028000000, null, 0) WHERE diagram_id = @id -- index:641
    UPDATE sysdiagrams SET [definition] .Write ( 0x290000002A0000002B0000002C0000002D0000002E0000002F00000030000000, null, 0) WHERE diagram_id = @id -- index:673
    UPDATE sysdiagrams SET [definition] .Write ( 0x3100000032000000330000003400000035000000360000003700000038000000, null, 0) WHERE diagram_id = @id -- index:705
    UPDATE sysdiagrams SET [definition] .Write ( 0x390000003A0000003B0000003C0000003D0000003E0000003F00000040000000, null, 0) WHERE diagram_id = @id -- index:737
    UPDATE sysdiagrams SET [definition] .Write ( 0x4100000042000000430000004400000045000000460000004700000048000000, null, 0) WHERE diagram_id = @id -- index:769
    UPDATE sysdiagrams SET [definition] .Write ( 0x490000004A0000004B0000004C0000004D0000004E0000004F00000050000000, null, 0) WHERE diagram_id = @id -- index:801
    UPDATE sysdiagrams SET [definition] .Write ( 0x5100000052000000530000005400000055000000560000005700000058000000, null, 0) WHERE diagram_id = @id -- index:833
    UPDATE sysdiagrams SET [definition] .Write ( 0x590000005A0000005B0000005C0000005D0000005E0000005F00000060000000, null, 0) WHERE diagram_id = @id -- index:865
    UPDATE sysdiagrams SET [definition] .Write ( 0x6100000062000000FEFFFFFFFEFFFFFFA0000000FEFFFFFFFDFFFFFF68000000, null, 0) WHERE diagram_id = @id -- index:897
    UPDATE sysdiagrams SET [definition] .Write ( 0x690000006A0000006B0000006C0000006D0000006E0000006F00000070000000, null, 0) WHERE diagram_id = @id -- index:929
    UPDATE sysdiagrams SET [definition] .Write ( 0x7100000072000000730000007400000075000000760000007700000078000000, null, 0) WHERE diagram_id = @id -- index:961
    UPDATE sysdiagrams SET [definition] .Write ( 0x790000007A0000007B0000007C0000007D0000007E0000007F00000080000000, null, 0) WHERE diagram_id = @id -- index:993
    UPDATE sysdiagrams SET [definition] .Write ( 0x52006F006F007400200045006E00740072007900000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1025
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1057
    UPDATE sysdiagrams SET [definition] .Write ( 0x16000500FFFFFFFFFFFFFFFF0200000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1089
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000605DD1260389D50164000000800C000000000000, null, 0) WHERE diagram_id = @id -- index:1121
    UPDATE sysdiagrams SET [definition] .Write ( 0x6600000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1153
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1185
    UPDATE sysdiagrams SET [definition] .Write ( 0x04000201FFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1217
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000000000000000002000000CA2F000000000000, null, 0) WHERE diagram_id = @id -- index:1249
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1281
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1313
    UPDATE sysdiagrams SET [definition] .Write ( 0x040002010100000004000000FFFFFFFF00000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1345
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000000000000000000001A0000003F90000000000000, null, 0) WHERE diagram_id = @id -- index:1377
    UPDATE sysdiagrams SET [definition] .Write ( 0x010043006F006D0070004F0062006A0000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1409
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1441
    UPDATE sysdiagrams SET [definition] .Write ( 0x12000201FFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:1473
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000005F00000000000000, null, 0) WHERE diagram_id = @id -- index:1505
    UPDATE sysdiagrams SET [definition] .Write ( 0x000430000A1E100C050000807E0000000F00FFFF7E000000007D0000B0960000, null, 0) WHERE diagram_id = @id -- index:1537
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E5D0000E90F0100BAA8020000000000B3320200DE805B10F195D011B0A000AA, null, 0) WHERE diagram_id = @id -- index:1569
    UPDATE sysdiagrams SET [definition] .Write ( 0x00BDCB5C0000080030000000000200000300000038002B00000009000000D9E6, null, 0) WHERE diagram_id = @id -- index:1601
    UPDATE sysdiagrams SET [definition] .Write ( 0xB0E91C81D011AD5100A0C90F5739F43B7F847F61C74385352986E1D552F8A032, null, 0) WHERE diagram_id = @id -- index:1633
    UPDATE sysdiagrams SET [definition] .Write ( 0x7DB2D86295428D98273C25A2DA2D00002C004320000000000000000000005344, null, 0) WHERE diagram_id = @id -- index:1665
    UPDATE sysdiagrams SET [definition] .Write ( 0x4DD2011FD1118E63006097D2DF4834C9D2777977D811907000065B840D9C0000, null, 0) WHERE diagram_id = @id -- index:1697
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0043200000000000000000000051444DD2011FD1118E63006097D2DF4834C9, null, 0) WHERE diagram_id = @id -- index:1729
    UPDATE sysdiagrams SET [definition] .Write ( 0xD2777977D811907000065B840D9C7E000000D42E000000FE01FF00004000A509, null, 0) WHERE diagram_id = @id -- index:1761
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000700008001000000B002000000800000150000805363684772696400F276, null, 0) WHERE diagram_id = @id -- index:1793
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000660201004469736369706C696E652028736E617073686F74290A00000000, null, 0) WHERE diagram_id = @id -- index:1825
    UPDATE sysdiagrams SET [definition] .Write ( 0x4400A50900000700008002000000BE020000008000001C000080536368477269, null, 0) WHERE diagram_id = @id -- index:1857
    UPDATE sysdiagrams SET [definition] .Write ( 0x6400CA5300002AF30000456C656D656E74446566696E6974696F6E2028736E61, null, 0) WHERE diagram_id = @id -- index:1889
    UPDATE sysdiagrams SET [definition] .Write ( 0x7073686F74290000A800A5090000070000800300000052000000018000007D00, null, 0) WHERE diagram_id = @id -- index:1921
    UPDATE sysdiagrams SET [definition] .Write ( 0x0080436F6E74726F6C00AA6C0000AB06010052656C6174696F6E736869702027, null, 0) WHERE diagram_id = @id -- index:1953
    UPDATE sysdiagrams SET [definition] .Write ( 0x464B5F4469736369706C696E655F456C656D656E74446566696E6974696F6E31, null, 0) WHERE diagram_id = @id -- index:1985
    UPDATE sysdiagrams SET [definition] .Write ( 0x2028736E617073686F742927206265747765656E2027456C656D656E74446566, null, 0) WHERE diagram_id = @id -- index:2017
    UPDATE sysdiagrams SET [definition] .Write ( 0x696E6974696F6E2028736E617073686F74292720616E6420274469736369706C, null, 0) WHERE diagram_id = @id -- index:2049
    UPDATE sysdiagrams SET [definition] .Write ( 0x696E652028736E617073686F742927CE782100002800B5010000070000800400, null, 0) WHERE diagram_id = @id -- index:2081
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000310000007300000002800000436F6E74726F6C00B66900003B0601000000, null, 0) WHERE diagram_id = @id -- index:2113
    UPDATE sysdiagrams SET [definition] .Write ( 0x4400A50900000700008005000000BA020000008000001A000080536368477269, null, 0) WHERE diagram_id = @id -- index:2145
    UPDATE sysdiagrams SET [definition] .Write ( 0x64008C550000DC500000456C656D656E74496E7374616E63652028736E617073, null, 0) WHERE diagram_id = @id -- index:2177
    UPDATE sysdiagrams SET [definition] .Write ( 0x686F742900000000B000A5090000070000800600000062000000018000008600, null, 0) WHERE diagram_id = @id -- index:2209
    UPDATE sysdiagrams SET [definition] .Write ( 0x0080436F6E74726F6C00175F0000508E000052656C6174696F6E736869702027, null, 0) WHERE diagram_id = @id -- index:2241
    UPDATE sysdiagrams SET [definition] .Write ( 0x464B5F456C656D656E74496E7374616E63655F456C656D656E74446566696E69, null, 0) WHERE diagram_id = @id -- index:2273
    UPDATE sysdiagrams SET [definition] .Write ( 0x74696F6E2028736E617073686F742927206265747765656E2027456C656D656E, null, 0) WHERE diagram_id = @id -- index:2305
    UPDATE sysdiagrams SET [definition] .Write ( 0x74446566696E6974696F6E2028736E617073686F74292720616E642027456C65, null, 0) WHERE diagram_id = @id -- index:2337
    UPDATE sysdiagrams SET [definition] .Write ( 0x6D656E74496E7374616E63652028736E617073686F742927460300002800B501, null, 0) WHERE diagram_id = @id -- index:2369
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000700008007000000310000007B00000002800000436F6E74726F6C005D61, null, 0) WHERE diagram_id = @id -- index:2401
    UPDATE sysdiagrams SET [definition] .Write ( 0x000052C1000000005400A50900000700008008000000DA020000008000002A00, null, 0) WHERE diagram_id = @id -- index:2433
    UPDATE sysdiagrams SET [definition] .Write ( 0x008053636847726964002C9700009CAE0000456C656D656E74496E7374616E63, null, 0) WHERE diagram_id = @id -- index:2465
    UPDATE sysdiagrams SET [definition] .Write ( 0x6544696D656E73696F6E5365676D656E742028736E617073686F742900000000, null, 0) WHERE diagram_id = @id -- index:2497
    UPDATE sysdiagrams SET [definition] .Write ( 0xCC00A509000007000080090000006200000001800000A2000080436F6E74726F, null, 0) WHERE diagram_id = @id -- index:2529
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C009B620000548E000052656C6174696F6E736869702027464B5F456C656D65, null, 0) WHERE diagram_id = @id -- index:2561
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74496E7374616E636544696D656E73696F6E5365676D656E745F456C656D65, null, 0) WHERE diagram_id = @id -- index:2593
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74496E7374616E63652028736E617073686F742927206265747765656E2027, null, 0) WHERE diagram_id = @id -- index:2625
    UPDATE sysdiagrams SET [definition] .Write ( 0x456C656D656E74496E7374616E63652028736E617073686F74292720616E6420, null, 0) WHERE diagram_id = @id -- index:2657
    UPDATE sysdiagrams SET [definition] .Write ( 0x27456C656D656E74496E7374616E636544696D656E73696F6E5365676D656E74, null, 0) WHERE diagram_id = @id -- index:2689
    UPDATE sysdiagrams SET [definition] .Write ( 0x2028736E617073686F742927BC2100002800B5010000070000800A0000003100, null, 0) WHERE diagram_id = @id -- index:2721
    UPDATE sysdiagrams SET [definition] .Write ( 0x00009700000002800000436F6E74726F6C001E5B00007DAD000000004800A509, null, 0) WHERE diagram_id = @id -- index:2753
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000070000800B000000C602000000800000200000805363684772696400F22B, null, 0) WHERE diagram_id = @id -- index:2785
    UPDATE sysdiagrams SET [definition] .Write ( 0x00009CAE0000456C656D656E74506172616D6574657256616C75652028736E61, null, 0) WHERE diagram_id = @id -- index:2817
    UPDATE sysdiagrams SET [definition] .Write ( 0x7073686F74290000BC00A5090000070000800C00000062000000018000009200, null, 0) WHERE diagram_id = @id -- index:2849
    UPDATE sysdiagrams SET [definition] .Write ( 0x0080436F6E74726F6C007949000051D7000052656C6174696F6E736869702027, null, 0) WHERE diagram_id = @id -- index:2881
    UPDATE sysdiagrams SET [definition] .Write ( 0x464B5F456C656D656E74506172616D6574657256616C75655F456C656D656E74, null, 0) WHERE diagram_id = @id -- index:2913
    UPDATE sysdiagrams SET [definition] .Write ( 0x446566696E6974696F6E2028736E617073686F742927206265747765656E2027, null, 0) WHERE diagram_id = @id -- index:2945
    UPDATE sysdiagrams SET [definition] .Write ( 0x456C656D656E74446566696E6974696F6E2028736E617073686F74292720616E, null, 0) WHERE diagram_id = @id -- index:2977
    UPDATE sysdiagrams SET [definition] .Write ( 0x642027456C656D656E74506172616D6574657256616C75652028736E61707368, null, 0) WHERE diagram_id = @id -- index:3009
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F742927000000002800B5010000070000800D00000031000000870000000280, null, 0) WHERE diagram_id = @id -- index:3041
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000436F6E74726F6C005D4D000074F000000000B800A5090000070000800E00, null, 0) WHERE diagram_id = @id -- index:3073
    UPDATE sysdiagrams SET [definition] .Write ( 0x000062000000018000008E000080436F6E74726F6C00B3390000548E00005265, null, 0) WHERE diagram_id = @id -- index:3105
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C6174696F6E736869702027464B5F456C656D656E74506172616D6574657256, null, 0) WHERE diagram_id = @id -- index:3137
    UPDATE sysdiagrams SET [definition] .Write ( 0x616C75655F456C656D656E74496E7374616E63652028736E617073686F742927, null, 0) WHERE diagram_id = @id -- index:3169
    UPDATE sysdiagrams SET [definition] .Write ( 0x206265747765656E2027456C656D656E74496E7374616E63652028736E617073, null, 0) WHERE diagram_id = @id -- index:3201
    UPDATE sysdiagrams SET [definition] .Write ( 0x686F74292720616E642027456C656D656E74506172616D6574657256616C7565, null, 0) WHERE diagram_id = @id -- index:3233
    UPDATE sysdiagrams SET [definition] .Write ( 0x2028736E617073686F742927000000002800B5010000070000800F0000003100, null, 0) WHERE diagram_id = @id -- index:3265
    UPDATE sysdiagrams SET [definition] .Write ( 0x00008300000002800000436F6E74726F6C00F740000013AA000000004000A509, null, 0) WHERE diagram_id = @id -- index:3297
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000700008010000000B202000000800000160000805363684772696400B80B, null, 0) WHERE diagram_id = @id -- index:3329
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005C0C0100456C656D656E74547970652028736E617073686F742900000000, null, 0) WHERE diagram_id = @id -- index:3361
    UPDATE sysdiagrams SET [definition] .Write ( 0xA800A5090000070000801100000062000000018000007F000080436F6E74726F, null, 0) WHERE diagram_id = @id -- index:3393
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00142100004107010052656C6174696F6E736869702027464B5F456C656D65, null, 0) WHERE diagram_id = @id -- index:3425
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74547970655F456C656D656E74446566696E6974696F6E312028736E617073, null, 0) WHERE diagram_id = @id -- index:3457
    UPDATE sysdiagrams SET [definition] .Write ( 0x686F742927206265747765656E2027456C656D656E74446566696E6974696F6E, null, 0) WHERE diagram_id = @id -- index:3489
    UPDATE sysdiagrams SET [definition] .Write ( 0x2028736E617073686F74292720616E642027456C656D656E7454797065202873, null, 0) WHERE diagram_id = @id -- index:3521
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E617073686F7429270000002800B50100000700008012000000310000007500, null, 0) WHERE diagram_id = @id -- index:3553
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002800000436F6E74726F6C00AD330000651801000000B000A50900000700, null, 0) WHERE diagram_id = @id -- index:3585
    UPDATE sysdiagrams SET [definition] .Write ( 0x008013000000620000000180000086000080436F6E74726F6C001421000051D7, null, 0) WHERE diagram_id = @id -- index:3617
    UPDATE sysdiagrams SET [definition] .Write ( 0x000052656C6174696F6E736869702027464B5F456C656D656E74506172616D65, null, 0) WHERE diagram_id = @id -- index:3649
    UPDATE sysdiagrams SET [definition] .Write ( 0x74657256616C75655F456C656D656E74547970652028736E617073686F742927, null, 0) WHERE diagram_id = @id -- index:3681
    UPDATE sysdiagrams SET [definition] .Write ( 0x206265747765656E2027456C656D656E74547970652028736E617073686F7429, null, 0) WHERE diagram_id = @id -- index:3713
    UPDATE sysdiagrams SET [definition] .Write ( 0x2720616E642027456C656D656E74506172616D6574657256616C75652028736E, null, 0) WHERE diagram_id = @id -- index:3745
    UPDATE sysdiagrams SET [definition] .Write ( 0x617073686F742927460300002800B50100000700008014000000310000007B00, null, 0) WHERE diagram_id = @id -- index:3777
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002800000436F6E74726F6C00D9120000ABF900000000A400A50900000700, null, 0) WHERE diagram_id = @id -- index:3809
    UPDATE sysdiagrams SET [definition] .Write ( 0x00801500000062000000018000007A000080436F6E74726F6C0043150000508E, null, 0) WHERE diagram_id = @id -- index:3841
    UPDATE sysdiagrams SET [definition] .Write ( 0x000052656C6174696F6E736869702027464B5F456C656D656E74496E7374616E, null, 0) WHERE diagram_id = @id -- index:3873
    UPDATE sysdiagrams SET [definition] .Write ( 0x63655F456C656D656E74547970652028736E617073686F742927206265747765, null, 0) WHERE diagram_id = @id -- index:3905
    UPDATE sysdiagrams SET [definition] .Write ( 0x656E2027456C656D656E74547970652028736E617073686F74292720616E6420, null, 0) WHERE diagram_id = @id -- index:3937
    UPDATE sysdiagrams SET [definition] .Write ( 0x27456C656D656E74496E7374616E63652028736E617073686F74292774290000, null, 0) WHERE diagram_id = @id -- index:3969
    UPDATE sysdiagrams SET [definition] .Write ( 0x2800B50100000700008016000000310000006F00000002800000436F6E74726F, null, 0) WHERE diagram_id = @id -- index:4001
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C004418000015AC000000005000A50900000700008017000000D40200000080, null, 0) WHERE diagram_id = @id -- index:4033
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000270000805363684772696400B0040000B0300100456C656D656E74547970, null, 0) WHERE diagram_id = @id -- index:4065
    UPDATE sysdiagrams SET [definition] .Write ( 0x65436F6E737472756374696F6E4C617965722028736E617073686F7429000000, null, 0) WHERE diagram_id = @id -- index:4097
    UPDATE sysdiagrams SET [definition] .Write ( 0xBC00A50900000700008018000000520000000180000094000080436F6E74726F, null, 0) WHERE diagram_id = @id -- index:4129
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00431500009F24010052656C6174696F6E736869702027464B5F456C656D65, null, 0) WHERE diagram_id = @id -- index:4161
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E7454797065436F6E737472756374696F6E4C617965725F456C656D656E7454, null, 0) WHERE diagram_id = @id -- index:4193
    UPDATE sysdiagrams SET [definition] .Write ( 0x7970652028736E617073686F742927206265747765656E2027456C656D656E74, null, 0) WHERE diagram_id = @id -- index:4225
    UPDATE sysdiagrams SET [definition] .Write ( 0x547970652028736E617073686F74292720616E642027456C656D656E74547970, null, 0) WHERE diagram_id = @id -- index:4257
    UPDATE sysdiagrams SET [definition] .Write ( 0x65436F6E737472756374696F6E4C617965722028736E617073686F7429270000, null, 0) WHERE diagram_id = @id -- index:4289
    UPDATE sysdiagrams SET [definition] .Write ( 0x2800B50100000700008019000000310000008900000002800000436F6E74726F, null, 0) WHERE diagram_id = @id -- index:4321
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0096FBFFFF572B010000004000A5090000070000801A000000B60200000080, null, 0) WHERE diagram_id = @id -- index:4353
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000180000805363684772696400F41A00004A79000047726F7570496E737461, null, 0) WHERE diagram_id = @id -- index:4385
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E63652028736E617073686F74290000B000A5090000070000801B0000006200, null, 0) WHERE diagram_id = @id -- index:4417
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000180000088000080436F6E74726F6C00BA300000E96E000052656C617469, null, 0) WHERE diagram_id = @id -- index:4449
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6E736869702027464B5F47726F7570496E7374616E63655F456C656D656E74, null, 0) WHERE diagram_id = @id -- index:4481
    UPDATE sysdiagrams SET [definition] .Write ( 0x496E7374616E63655F4F776E6572566965772028736E617073686F7429272062, null, 0) WHERE diagram_id = @id -- index:4513
    UPDATE sysdiagrams SET [definition] .Write ( 0x65747765656E2027456C656D656E74496E7374616E63652028736E617073686F, null, 0) WHERE diagram_id = @id -- index:4545
    UPDATE sysdiagrams SET [definition] .Write ( 0x74292720616E64202747726F7570496E7374616E63652028736E617073686F74, null, 0) WHERE diagram_id = @id -- index:4577
    UPDATE sysdiagrams SET [definition] .Write ( 0x292700002800B5010000070000801C000000310000008700000002800000436F, null, 0) WHERE diagram_id = @id -- index:4609
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C00483300001C8800000000AC00A5090000070000801D0000006200, null, 0) WHERE diagram_id = @id -- index:4641
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000180000084000080436F6E74726F6C00BA300000AB70000052656C617469, null, 0) WHERE diagram_id = @id -- index:4673
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6E736869702027464B5F47726F7570496E7374616E63655F456C656D656E74, null, 0) WHERE diagram_id = @id -- index:4705
    UPDATE sysdiagrams SET [definition] .Write ( 0x496E7374616E63655F4C6576656C2028736E617073686F742927206265747765, null, 0) WHERE diagram_id = @id -- index:4737
    UPDATE sysdiagrams SET [definition] .Write ( 0x656E2027456C656D656E74496E7374616E63652028736E617073686F74292720, null, 0) WHERE diagram_id = @id -- index:4769
    UPDATE sysdiagrams SET [definition] .Write ( 0x616E64202747726F7570496E7374616E63652028736E617073686F7429270000, null, 0) WHERE diagram_id = @id -- index:4801
    UPDATE sysdiagrams SET [definition] .Write ( 0x2800B5010000070000801E000000310000007F00000002800000436F6E74726F, null, 0) WHERE diagram_id = @id -- index:4833
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0041370000978A000000005800A5090000070000801F000000E00200000080, null, 0) WHERE diagram_id = @id -- index:4865
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002D0000805363684772696400922200009C63000047726F7570496E737461, null, 0) WHERE diagram_id = @id -- index:4897
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E6365456C656D656E74496E7374616E63654C6F6F6B75702028736E61707368, null, 0) WHERE diagram_id = @id -- index:4929
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F74290000000000D000A509000007000080200000006200000001800000A800, null, 0) WHERE diagram_id = @id -- index:4961
    UPDATE sysdiagrams SET [definition] .Write ( 0x0080436F6E74726F6C005D4B0000FD67000052656C6174696F6E736869702027, null, 0) WHERE diagram_id = @id -- index:4993
    UPDATE sysdiagrams SET [definition] .Write ( 0x464B5F47726F7570496E7374616E6365456C656D656E74496E7374616E63654C, null, 0) WHERE diagram_id = @id -- index:5025
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6F6B75705F456C656D656E74496E7374616E63652028736E617073686F7429, null, 0) WHERE diagram_id = @id -- index:5057
    UPDATE sysdiagrams SET [definition] .Write ( 0x27206265747765656E2027456C656D656E74496E7374616E63652028736E6170, null, 0) WHERE diagram_id = @id -- index:5089
    UPDATE sysdiagrams SET [definition] .Write ( 0x73686F74292720616E64202747726F7570496E7374616E6365456C656D656E74, null, 0) WHERE diagram_id = @id -- index:5121
    UPDATE sysdiagrams SET [definition] .Write ( 0x496E7374616E63654C6F6F6B75702028736E617073686F74292700002800B501, null, 0) WHERE diagram_id = @id -- index:5153
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000700008021000000310000009D00000002800000436F6E74726F6C00332D, null, 0) WHERE diagram_id = @id -- index:5185
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000656F00000000CC00A509000007000080220000006200000001800000A400, null, 0) WHERE diagram_id = @id -- index:5217
    UPDATE sysdiagrams SET [definition] .Write ( 0x0080436F6E74726F6C00AB250000F96C000052656C6174696F6E736869702027, null, 0) WHERE diagram_id = @id -- index:5249
    UPDATE sysdiagrams SET [definition] .Write ( 0x464B5F47726F7570496E7374616E6365456C656D656E74496E7374616E63654C, null, 0) WHERE diagram_id = @id -- index:5281
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6F6B75705F47726F7570496E7374616E63652028736E617073686F74292720, null, 0) WHERE diagram_id = @id -- index:5313
    UPDATE sysdiagrams SET [definition] .Write ( 0x6265747765656E202747726F7570496E7374616E63652028736E617073686F74, null, 0) WHERE diagram_id = @id -- index:5345
    UPDATE sysdiagrams SET [definition] .Write ( 0x292720616E64202747726F7570496E7374616E6365456C656D656E74496E7374, null, 0) WHERE diagram_id = @id -- index:5377
    UPDATE sysdiagrams SET [definition] .Write ( 0x616E63654C6F6F6B75702028736E617073686F74292700002800B50100000700, null, 0) WHERE diagram_id = @id -- index:5409
    UPDATE sysdiagrams SET [definition] .Write ( 0x008023000000310000009900000002800000436F6E74726F6C00D52D0000DE72, null, 0) WHERE diagram_id = @id -- index:5441
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000005000A50900000700008024000000D202000000800000260000805363, null, 0) WHERE diagram_id = @id -- index:5473
    UPDATE sysdiagrams SET [definition] .Write ( 0x68477269640000000000C43B000047726F7570496E7374616E6365506172616D, null, 0) WHERE diagram_id = @id -- index:5505
    UPDATE sysdiagrams SET [definition] .Write ( 0x6574657256616C75652028736E617073686F742900000000C000A50900000700, null, 0) WHERE diagram_id = @id -- index:5537
    UPDATE sysdiagrams SET [definition] .Write ( 0x008025000000620000000180000097000080436F6E74726F6C00D30A0000D16C, null, 0) WHERE diagram_id = @id -- index:5569
    UPDATE sysdiagrams SET [definition] .Write ( 0x000052656C6174696F6E736869702027464B5F47726F7570496E7374616E6365, null, 0) WHERE diagram_id = @id -- index:5601
    UPDATE sysdiagrams SET [definition] .Write ( 0x506172616D6574657256616C75655F47726F7570496E7374616E636531202873, null, 0) WHERE diagram_id = @id -- index:5633
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E617073686F742927206265747765656E202747726F7570496E7374616E6365, null, 0) WHERE diagram_id = @id -- index:5665
    UPDATE sysdiagrams SET [definition] .Write ( 0x2028736E617073686F74292720616E64202747726F7570496E7374616E636550, null, 0) WHERE diagram_id = @id -- index:5697
    UPDATE sysdiagrams SET [definition] .Write ( 0x6172616D6574657256616C75652028736E617073686F7429270000002800B501, null, 0) WHERE diagram_id = @id -- index:5729
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000700008026000000310000008D00000002800000436F6E74726F6C00D21B, null, 0) WHERE diagram_id = @id -- index:5761
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002870000000004000A50900000700008027000000B2020000008000001600, null, 0) WHERE diagram_id = @id -- index:5793
    UPDATE sysdiagrams SET [definition] .Write ( 0x0080536368477269640036420000A8BF01004C696E655061747465726E202873, null, 0) WHERE diagram_id = @id -- index:5825
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E617073686F7429742900003800A50900000700008028000000A20200000080, null, 0) WHERE diagram_id = @id -- index:5857
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000E0000805363684772696400CC8D00004E5700004C6F67416464496E2028, null, 0) WHERE diagram_id = @id -- index:5889
    UPDATE sysdiagrams SET [definition] .Write ( 0x70616C29000000003800A50900000700008029000000A2020000008000000E00, null, 0) WHERE diagram_id = @id -- index:5921
    UPDATE sysdiagrams SET [definition] .Write ( 0x00805363684772696400CC8D0000546F00004C6F674372617368202870616C29, null, 0) WHERE diagram_id = @id -- index:5953
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000003C00A5090000070000802A000000AC02000000800000130000805363, null, 0) WHERE diagram_id = @id -- index:5985
    UPDATE sysdiagrams SET [definition] .Write ( 0x68477269640006AE0000167100004C6F67446F6353657373696F6E202870616C, null, 0) WHERE diagram_id = @id -- index:6017
    UPDATE sysdiagrams SET [definition] .Write ( 0x296F00008C00A5090000070000802B000000620000000180000061000080436F, null, 0) WHERE diagram_id = @id -- index:6049
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C00739700002663000052656C6174696F6E736869702027464B5F4C, null, 0) WHERE diagram_id = @id -- index:6081
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F67416464496E5F4C6F67446F6353657373696F6E202870616C292720626574, null, 0) WHERE diagram_id = @id -- index:6113
    UPDATE sysdiagrams SET [definition] .Write ( 0x7765656E20274C6F67446F6353657373696F6E202870616C292720616E642027, null, 0) WHERE diagram_id = @id -- index:6145
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C6F67416464496E202870616C292700000000002800B5010000070000802C00, null, 0) WHERE diagram_id = @id -- index:6177
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000310000006500000002800000436F6E74726F6C00199B00000A6900000000, null, 0) WHERE diagram_id = @id -- index:6209
    UPDATE sysdiagrams SET [definition] .Write ( 0x8C00A5090000070000802D000000620000000180000061000080436F6E74726F, null, 0) WHERE diagram_id = @id -- index:6241
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0028A300007F7C000052656C6174696F6E736869702027464B5F4C6F674372, null, 0) WHERE diagram_id = @id -- index:6273
    UPDATE sysdiagrams SET [definition] .Write ( 0x6173685F4C6F67446F6353657373696F6E202870616C2927206265747765656E, null, 0) WHERE diagram_id = @id -- index:6305
    UPDATE sysdiagrams SET [definition] .Write ( 0x20274C6F67446F6353657373696F6E202870616C292720616E6420274C6F6743, null, 0) WHERE diagram_id = @id -- index:6337
    UPDATE sysdiagrams SET [definition] .Write ( 0x72617368202870616C2927006E0000002800B5010000070000802E0000003100, null, 0) WHERE diagram_id = @id -- index:6369
    UPDATE sysdiagrams SET [definition] .Write ( 0x00006500000002800000436F6E74726F6C002A9700000199000000004400A509, null, 0) WHERE diagram_id = @id -- index:6401
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000070000802F000000BC020000008000001B0000805363684772696400AACD, null, 0) WHERE diagram_id = @id -- index:6433
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000528000004C6F67446F63756D656E7450726F6A4368616E6765202870616C, null, 0) WHERE diagram_id = @id -- index:6465
    UPDATE sysdiagrams SET [definition] .Write ( 0x29000000A400A5090000070000803000000062000000018000007B000080436F, null, 0) WHERE diagram_id = @id -- index:6497
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C0062C30000F989000052656C6174696F6E736869702027464B5F4C, null, 0) WHERE diagram_id = @id -- index:6529
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F67446F63756D656E7450726F6A4368616E67655F4C6F67446F635365737369, null, 0) WHERE diagram_id = @id -- index:6561
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6E202870616C2927206265747765656E20274C6F67446F6353657373696F6E, null, 0) WHERE diagram_id = @id -- index:6593
    UPDATE sysdiagrams SET [definition] .Write ( 0x202870616C292720616E6420274C6F67446F63756D656E7450726F6A4368616E, null, 0) WHERE diagram_id = @id -- index:6625
    UPDATE sysdiagrams SET [definition] .Write ( 0x6765202870616C29270000002800B50100000700008031000000310000007F00, null, 0) WHERE diagram_id = @id -- index:6657
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002800000436F6E74726F6C00A5CB0000469F000000003800A50900000700, null, 0) WHERE diagram_id = @id -- index:6689
    UPDATE sysdiagrams SET [definition] .Write ( 0x008032000000A6020000008000001000008053636847726964009CAE000032FA, null, 0) WHERE diagram_id = @id -- index:6721
    UPDATE sysdiagrams SET [definition] .Write ( 0x00004C6F67456C656D656E74202870616C2900009000A5090000070000803300, null, 0) WHERE diagram_id = @id -- index:6753
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000620000000180000065000080436F6E74726F6C0091B7000091EC00005265, null, 0) WHERE diagram_id = @id -- index:6785
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C6174696F6E736869702027464B5F4C6F67456C656D656E745F4C6F67446F63, null, 0) WHERE diagram_id = @id -- index:6817
    UPDATE sysdiagrams SET [definition] .Write ( 0x53657373696F6E202870616C2927206265747765656E20274C6F67446F635365, null, 0) WHERE diagram_id = @id -- index:6849
    UPDATE sysdiagrams SET [definition] .Write ( 0x7373696F6E202870616C292720616E6420274C6F67456C656D656E7420287061, null, 0) WHERE diagram_id = @id -- index:6881
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C292700000000002800B5010000070000803400000031000000690000000280, null, 0) WHERE diagram_id = @id -- index:6913
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000436F6E74726F6C0093A700007BF5000000003800A5090000070000803500, null, 0) WHERE diagram_id = @id -- index:6945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000A0020000008000000D00008053636847726964008A660000000000004C6F, null, 0) WHERE diagram_id = @id -- index:6977
    UPDATE sysdiagrams SET [definition] .Write ( 0x67454E554D202870616C2929000000003800A50900000700008036000000A202, null, 0) WHERE diagram_id = @id -- index:7009
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000008000000E0000805363684772696400CC8D0000009600004C6F67457665, null, 0) WHERE diagram_id = @id -- index:7041
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74202870616C296C2900008C00A50900000700008037000000620000000180, null, 0) WHERE diagram_id = @id -- index:7073
    UPDATE sysdiagrams SET [definition] .Write ( 0x000061000080436F6E74726F6C0028A3000031AE000052656C6174696F6E7368, null, 0) WHERE diagram_id = @id -- index:7105
    UPDATE sysdiagrams SET [definition] .Write ( 0x69702027464B5F4C6F674576656E745F4C6F67446F6353657373696F6E202870, null, 0) WHERE diagram_id = @id -- index:7137
    UPDATE sysdiagrams SET [definition] .Write ( 0x616C2927206265747765656E20274C6F67446F6353657373696F6E202870616C, null, 0) WHERE diagram_id = @id -- index:7169
    UPDATE sysdiagrams SET [definition] .Write ( 0x292720616E6420274C6F674576656E74202870616C292700000000002800B501, null, 0) WHERE diagram_id = @id -- index:7201
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000700008038000000310000006500000002800000436F6E74726F6C00F298, null, 0) WHERE diagram_id = @id -- index:7233
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000C1AD000000003800A50900000700008039000000A0020000008000000D00, null, 0) WHERE diagram_id = @id -- index:7265
    UPDATE sysdiagrams SET [definition] .Write ( 0x00805363684772696400AACD0000A2C600004C6F674C696E6B202870616C2909, null, 0) WHERE diagram_id = @id -- index:7297
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000008800A5090000070000803A00000062000000018000005F000080436F, null, 0) WHERE diagram_id = @id -- index:7329
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C0062C30000F3AF000052656C6174696F6E736869702027464B5F4C, null, 0) WHERE diagram_id = @id -- index:7361
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F674C696E6B5F4C6F67446F6353657373696F6E202870616C29272062657477, null, 0) WHERE diagram_id = @id -- index:7393
    UPDATE sysdiagrams SET [definition] .Write ( 0x65656E20274C6F67446F6353657373696F6E202870616C292720616E6420274C, null, 0) WHERE diagram_id = @id -- index:7425
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F674C696E6B202870616C29270000002800B5010000070000803B0000003100, null, 0) WHERE diagram_id = @id -- index:7457
    UPDATE sysdiagrams SET [definition] .Write ( 0x00006300000002800000436F6E74726F6C0056BC000068C0000000003800A509, null, 0) WHERE diagram_id = @id -- index:7489
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000070000803C000000A602000000800000100000805363684772696400AACD, null, 0) WHERE diagram_id = @id -- index:7521
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000C43B00004C6F674D616368696E65202870616C2900009000A50900000700, null, 0) WHERE diagram_id = @id -- index:7553
    UPDATE sysdiagrams SET [definition] .Write ( 0x00803D000000620000000180000065000080436F6E74726F6C0053B900007464, null, 0) WHERE diagram_id = @id -- index:7585
    UPDATE sysdiagrams SET [definition] .Write ( 0x000052656C6174696F6E736869702027464B5F4C6F674D616368696E655F4C6F, null, 0) WHERE diagram_id = @id -- index:7617
    UPDATE sysdiagrams SET [definition] .Write ( 0x67446F6353657373696F6E202870616C2927206265747765656E20274C6F6744, null, 0) WHERE diagram_id = @id -- index:7649
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6353657373696F6E202870616C292720616E6420274C6F674D616368696E65, null, 0) WHERE diagram_id = @id -- index:7681
    UPDATE sysdiagrams SET [definition] .Write ( 0x202870616C292700000000002800B5010000070000803E000000310000006900, null, 0) WHERE diagram_id = @id -- index:7713
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002800000436F6E74726F6C003EC80000BE69000000003800A50900000700, null, 0) WHERE diagram_id = @id -- index:7745
    UPDATE sysdiagrams SET [definition] .Write ( 0x00803F000000A2020000008000000E0000805363684772696400CC8D0000F0D2, null, 0) WHERE diagram_id = @id -- index:7777
    UPDATE sysdiagrams SET [definition] .Write ( 0x00004C6F675072696E74202870616C29000000008C00A5090000070000804000, null, 0) WHERE diagram_id = @id -- index:7809
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000620000000180000061000080436F6E74726F6C0028A30000F3AF00005265, null, 0) WHERE diagram_id = @id -- index:7841
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C6174696F6E736869702027464B5F4C6F675072696E745F4C6F67446F635365, null, 0) WHERE diagram_id = @id -- index:7873
    UPDATE sysdiagrams SET [definition] .Write ( 0x7373696F6E202870616C2927206265747765656E20274C6F67446F6353657373, null, 0) WHERE diagram_id = @id -- index:7905
    UPDATE sysdiagrams SET [definition] .Write ( 0x696F6E202870616C292720616E6420274C6F675072696E74202870616C292700, null, 0) WHERE diagram_id = @id -- index:7937
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000002800B50100000700008041000000310000006500000002800000436F, null, 0) WHERE diagram_id = @id -- index:7969
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C002397000046C5000000003800A50900000700008042000000A602, null, 0) WHERE diagram_id = @id -- index:8001
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000800000100000805363684772696400FC210000000000004C6F67536573, null, 0) WHERE diagram_id = @id -- index:8033
    UPDATE sysdiagrams SET [definition] .Write ( 0x73696F6E202870616C2900003800A50900000700008043000000A60200000080, null, 0) WHERE diagram_id = @id -- index:8065
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001000008053636847726964008E440000000000004C6F6753657474696E67, null, 0) WHERE diagram_id = @id -- index:8097
    UPDATE sysdiagrams SET [definition] .Write ( 0x202870616C2900003800A50900000700008044000000A6020000008000001000, null, 0) WHERE diagram_id = @id -- index:8129
    UPDATE sysdiagrams SET [definition] .Write ( 0x0080536368477269640040CE000032FA00004C6F6753756D6D61727920287061, null, 0) WHERE diagram_id = @id -- index:8161
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C2900009000A50900000700008045000000620000000180000065000080436F, null, 0) WHERE diagram_id = @id -- index:8193
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C0053B9000091EC000052656C6174696F6E736869702027464B5F4C, null, 0) WHERE diagram_id = @id -- index:8225
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6753756D6D6172795F4C6F67446F6353657373696F6E202870616C29272062, null, 0) WHERE diagram_id = @id -- index:8257
    UPDATE sysdiagrams SET [definition] .Write ( 0x65747765656E20274C6F67446F6353657373696F6E202870616C292720616E64, null, 0) WHERE diagram_id = @id -- index:8289
    UPDATE sysdiagrams SET [definition] .Write ( 0x20274C6F6753756D6D617279202870616C292700000000002800B50100000700, null, 0) WHERE diagram_id = @id -- index:8321
    UPDATE sysdiagrams SET [definition] .Write ( 0x008046000000310000006900000002800000436F6E74726F6C0052B50000FEF7, null, 0) WHERE diagram_id = @id -- index:8353
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000003C00A50900000700008047000000A802000000800000110000805363, null, 0) WHERE diagram_id = @id -- index:8385
    UPDATE sysdiagrams SET [definition] .Write ( 0x68477269640006AE0000F65400004C6F675669657754797065202870616C2973, null, 0) WHERE diagram_id = @id -- index:8417
    UPDATE sysdiagrams SET [definition] .Write ( 0x686F00009000A50900000700008048000000620000000180000067000080436F, null, 0) WHERE diagram_id = @id -- index:8449
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C0091B700004963000052656C6174696F6E736869702027464B5F4C, null, 0) WHERE diagram_id = @id -- index:8481
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6756696577547970655F4C6F67446F6353657373696F6E202870616C292720, null, 0) WHERE diagram_id = @id -- index:8513
    UPDATE sysdiagrams SET [definition] .Write ( 0x6265747765656E20274C6F67446F6353657373696F6E202870616C292720616E, null, 0) WHERE diagram_id = @id -- index:8545
    UPDATE sysdiagrams SET [definition] .Write ( 0x6420274C6F675669657754797065202870616C29274600002800B50100000700, null, 0) WHERE diagram_id = @id -- index:8577
    UPDATE sysdiagrams SET [definition] .Write ( 0x008049000000310000006B00000002800000436F6E74726F6C00D7B900007E6B, null, 0) WHERE diagram_id = @id -- index:8609
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000003800A5090000070000804A000000A602000000800000100000805363, null, 0) WHERE diagram_id = @id -- index:8641
    UPDATE sysdiagrams SET [definition] .Write ( 0x684772696400AACD0000F69F00004C6F675761726E696E67202870616C290000, null, 0) WHERE diagram_id = @id -- index:8673
    UPDATE sysdiagrams SET [definition] .Write ( 0x9000A5090000070000804B000000620000000180000065000080436F6E74726F, null, 0) WHERE diagram_id = @id -- index:8705
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0062C3000021AD000052656C6174696F6E736869702027464B5F4C6F675761, null, 0) WHERE diagram_id = @id -- index:8737
    UPDATE sysdiagrams SET [definition] .Write ( 0x726E696E675F4C6F67446F6353657373696F6E202870616C2927206265747765, null, 0) WHERE diagram_id = @id -- index:8769
    UPDATE sysdiagrams SET [definition] .Write ( 0x656E20274C6F67446F6353657373696F6E202870616C292720616E6420274C6F, null, 0) WHERE diagram_id = @id -- index:8801
    UPDATE sysdiagrams SET [definition] .Write ( 0x675761726E696E67202870616C292729274600002800B5010000070000804C00, null, 0) WHERE diagram_id = @id -- index:8833
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000310000006900000002800000436F6E74726F6C0030CA000077B000000000, null, 0) WHERE diagram_id = @id -- index:8865
    UPDATE sysdiagrams SET [definition] .Write ( 0x4000A5090000070000804D000000B40200000080000017000080536368477269, null, 0) WHERE diagram_id = @id -- index:8897
    UPDATE sysdiagrams SET [definition] .Write ( 0x6400368D000032FA00004C6F675761726E696E6753756D6D617279202870616C, null, 0) WHERE diagram_id = @id -- index:8929
    UPDATE sysdiagrams SET [definition] .Write ( 0x290000009C00A5090000070000804E000000620000000180000073000080436F, null, 0) WHERE diagram_id = @id -- index:8961
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C000998000091EC000052656C6174696F6E736869702027464B5F4C, null, 0) WHERE diagram_id = @id -- index:8993
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F675761726E696E6753756D6D6172795F4C6F67446F6353657373696F6E2028, null, 0) WHERE diagram_id = @id -- index:9025
    UPDATE sysdiagrams SET [definition] .Write ( 0x70616C2927206265747765656E20274C6F67446F6353657373696F6E20287061, null, 0) WHERE diagram_id = @id -- index:9057
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C292720616E6420274C6F675761726E696E6753756D6D617279202870616C29, null, 0) WHERE diagram_id = @id -- index:9089
    UPDATE sysdiagrams SET [definition] .Write ( 0x270000002800B5010000070000804F000000310000007700000002800000436F, null, 0) WHERE diagram_id = @id -- index:9121
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C00F8940000FCF5000000003800A50900000700008050000000A402, null, 0) WHERE diagram_id = @id -- index:9153
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000008000000F0000805363684772696400AC7100009E52000050726F6A6563, null, 0) WHERE diagram_id = @id -- index:9185
    UPDATE sysdiagrams SET [definition] .Write ( 0x7420286173736574292900004000A50900000700008051000000B20200000080, null, 0) WHERE diagram_id = @id -- index:9217
    UPDATE sysdiagrams SET [definition] .Write ( 0x000016000080536368477269640064C80000582E010050726F6A65637446696C, null, 0) WHERE diagram_id = @id -- index:9249
    UPDATE sysdiagrams SET [definition] .Write ( 0x652028736E617073686F7429000000004800A50900000700008052000000C202, null, 0) WHERE diagram_id = @id -- index:9281
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000008000001E0000805363684772696400DA6100000E4B010050726F6A6563, null, 0) WHERE diagram_id = @id -- index:9313
    UPDATE sysdiagrams SET [definition] .Write ( 0x7446696C65536E617073686F742028736E617073686F742900000000AC00A509, null, 0) WHERE diagram_id = @id -- index:9345
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000700008053000000620000000180000082000080436F6E74726F6C005D71, null, 0) WHERE diagram_id = @id -- index:9377
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002A3F010052656C6174696F6E736869702027464B5F50726F6A6563744669, null, 0) WHERE diagram_id = @id -- index:9409
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C65536E617073686F745F50726F6A65637446696C652028736E617073686F74, null, 0) WHERE diagram_id = @id -- index:9441
    UPDATE sysdiagrams SET [definition] .Write ( 0x2927206265747765656E202750726F6A65637446696C652028736E617073686F, null, 0) WHERE diagram_id = @id -- index:9473
    UPDATE sysdiagrams SET [definition] .Write ( 0x74292720616E64202750726F6A65637446696C65536E617073686F742028736E, null, 0) WHERE diagram_id = @id -- index:9505
    UPDATE sysdiagrams SET [definition] .Write ( 0x617073686F742927650000002800B50100000700008054000000310000007700, null, 0) WHERE diagram_id = @id -- index:9537
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002800000436F6E74726F6C00EE860000544301000000AC00A50900000700, null, 0) WHERE diagram_id = @id -- index:9569
    UPDATE sysdiagrams SET [definition] .Write ( 0x008055000000520000000180000082000080436F6E74726F6C009257000019C5, null, 0) WHERE diagram_id = @id -- index:9601
    UPDATE sysdiagrams SET [definition] .Write ( 0x010052656C6174696F6E736869702027464B5F4C696E655061747465726E5F50, null, 0) WHERE diagram_id = @id -- index:9633
    UPDATE sysdiagrams SET [definition] .Write ( 0x726F6A65637446696C65536E617073686F742028736E617073686F7429272062, null, 0) WHERE diagram_id = @id -- index:9665
    UPDATE sysdiagrams SET [definition] .Write ( 0x65747765656E202750726F6A65637446696C65536E617073686F742028736E61, null, 0) WHERE diagram_id = @id -- index:9697
    UPDATE sysdiagrams SET [definition] .Write ( 0x7073686F74292720616E6420274C696E655061747465726E2028736E61707368, null, 0) WHERE diagram_id = @id -- index:9729
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F742927404000002800B5010000070000805600000031000000770000000280, null, 0) WHERE diagram_id = @id -- index:9761
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000436F6E74726F6C00C4530000A9C401000000B800A5090000070000805700, null, 0) WHERE diagram_id = @id -- index:9793
    UPDATE sysdiagrams SET [definition] .Write ( 0x000062000000018000008E000080436F6E74726F6C00335F00004B1A01005265, null, 0) WHERE diagram_id = @id -- index:9825
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C6174696F6E736869702027464B5F456C656D656E74446566696E6974696F6E, null, 0) WHERE diagram_id = @id -- index:9857
    UPDATE sysdiagrams SET [definition] .Write ( 0x5F50726F6A65637446696C65536E617073686F742028736E617073686F742927, null, 0) WHERE diagram_id = @id -- index:9889
    UPDATE sysdiagrams SET [definition] .Write ( 0x206265747765656E202750726F6A65637446696C65536E617073686F74202873, null, 0) WHERE diagram_id = @id -- index:9921
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E617073686F74292720616E642027456C656D656E74446566696E6974696F6E, null, 0) WHERE diagram_id = @id -- index:9953
    UPDATE sysdiagrams SET [definition] .Write ( 0x2028736E617073686F742927000000002800B501000007000080580000003100, null, 0) WHERE diagram_id = @id -- index:9985
    UPDATE sysdiagrams SET [definition] .Write ( 0x00008300000002800000436F6E74726F6C005D610000F33801000000B000A509, null, 0) WHERE diagram_id = @id -- index:10017
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000700008059000000620000000180000086000080436F6E74726F6C003125, null, 0) WHERE diagram_id = @id -- index:10049
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000E6A2000052656C6174696F6E736869702027464B5F47726F7570496E7374, null, 0) WHERE diagram_id = @id -- index:10081
    UPDATE sysdiagrams SET [definition] .Write ( 0x616E63655F50726F6A65637446696C65536E617073686F742028736E61707368, null, 0) WHERE diagram_id = @id -- index:10113
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F742927206265747765656E202750726F6A65637446696C65536E617073686F, null, 0) WHERE diagram_id = @id -- index:10145
    UPDATE sysdiagrams SET [definition] .Write ( 0x742028736E617073686F74292720616E64202747726F7570496E7374616E6365, null, 0) WHERE diagram_id = @id -- index:10177
    UPDATE sysdiagrams SET [definition] .Write ( 0x2028736E617073686F742927460300002800B5010000070000805A0000003100, null, 0) WHERE diagram_id = @id -- index:10209
    UPDATE sysdiagrams SET [definition] .Write ( 0x00007B00000002800000436F6E74726F6C005B2700006B19010000004800A509, null, 0) WHERE diagram_id = @id -- index:10241
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000070000805B000000C4020000008000001F0000805363684772696400F276, null, 0) WHERE diagram_id = @id -- index:10273
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000484C020050726F6A656374496E666F506172616D657465722028736E6170, null, 0) WHERE diagram_id = @id -- index:10305
    UPDATE sysdiagrams SET [definition] .Write ( 0x73686F7429000000BC00A5090000070000805C00000062000000018000009400, null, 0) WHERE diagram_id = @id -- index:10337
    UPDATE sysdiagrams SET [definition] .Write ( 0x0080436F6E74726F6C00536E00001440020052656C6174696F6E736869702027, null, 0) WHERE diagram_id = @id -- index:10369
    UPDATE sysdiagrams SET [definition] .Write ( 0x464B5F50726F6A656374496E666F506172616D657465725F50726F6A65637446, null, 0) WHERE diagram_id = @id -- index:10401
    UPDATE sysdiagrams SET [definition] .Write ( 0x696C65536E617073686F742028736E617073686F742927206265747765656E20, null, 0) WHERE diagram_id = @id -- index:10433
    UPDATE sysdiagrams SET [definition] .Write ( 0x2750726F6A65637446696C65536E617073686F742028736E617073686F742927, null, 0) WHERE diagram_id = @id -- index:10465
    UPDATE sysdiagrams SET [definition] .Write ( 0x20616E64202750726F6A656374496E666F506172616D657465722028736E6170, null, 0) WHERE diagram_id = @id -- index:10497
    UPDATE sysdiagrams SET [definition] .Write ( 0x73686F74292700002800B5010000070000805D00000031000000890000000280, null, 0) WHERE diagram_id = @id -- index:10529
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000436F6E74726F6C0002830000DF47020000004C00A5090000070000805E00, null, 0) WHERE diagram_id = @id -- index:10561
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000CC02000000800000230000805363684772696400C24C00009C7002005072, null, 0) WHERE diagram_id = @id -- index:10593
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6A656374506172616D6574657243617465676F72792028736E617073686F74, null, 0) WHERE diagram_id = @id -- index:10625
    UPDATE sysdiagrams SET [definition] .Write ( 0x290000005000A5090000070000805F000000D002000000800000250000805363, null, 0) WHERE diagram_id = @id -- index:10657
    UPDATE sysdiagrams SET [definition] .Write ( 0x6847726964002C4C0000484C020050726F6A656374506172616D657465724465, null, 0) WHERE diagram_id = @id -- index:10689
    UPDATE sysdiagrams SET [definition] .Write ( 0x66696E6974696F6E2028736E617073686F74290000000000D400A50900000700, null, 0) WHERE diagram_id = @id -- index:10721
    UPDATE sysdiagrams SET [definition] .Write ( 0x0080600000005200000001800000AB000080436F6E74726F6C00FD5A00008B64, null, 0) WHERE diagram_id = @id -- index:10753
    UPDATE sysdiagrams SET [definition] .Write ( 0x020052656C6174696F6E736869702027464B5F50726F6A656374506172616D65, null, 0) WHERE diagram_id = @id -- index:10785
    UPDATE sysdiagrams SET [definition] .Write ( 0x74657243617465676F72795F50726F6A656374506172616D6574657244656669, null, 0) WHERE diagram_id = @id -- index:10817
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E6974696F6E312028736E617073686F742927206265747765656E202750726F, null, 0) WHERE diagram_id = @id -- index:10849
    UPDATE sysdiagrams SET [definition] .Write ( 0x6A656374506172616D65746572446566696E6974696F6E2028736E617073686F, null, 0) WHERE diagram_id = @id -- index:10881
    UPDATE sysdiagrams SET [definition] .Write ( 0x74292720616E64202750726F6A656374506172616D6574657243617465676F72, null, 0) WHERE diagram_id = @id -- index:10913
    UPDATE sysdiagrams SET [definition] .Write ( 0x792028736E617073686F7429270000002800B501000007000080610000003100, null, 0) WHERE diagram_id = @id -- index:10945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000A100000002800000436F6E74726F6C00743B0000026B02000000C800A509, null, 0) WHERE diagram_id = @id -- index:10977
    UPDATE sysdiagrams SET [definition] .Write ( 0x000007000080620000006200000001800000A0000080436F6E74726F6C00195B, null, 0) WHERE diagram_id = @id -- index:11009
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001440020052656C6174696F6E736869702027464B5F50726F6A6563745061, null, 0) WHERE diagram_id = @id -- index:11041
    UPDATE sysdiagrams SET [definition] .Write ( 0x72616D65746572446566696E6974696F6E5F50726F6A65637446696C65536E61, null, 0) WHERE diagram_id = @id -- index:11073
    UPDATE sysdiagrams SET [definition] .Write ( 0x7073686F742028736E617073686F742927206265747765656E202750726F6A65, null, 0) WHERE diagram_id = @id -- index:11105
    UPDATE sysdiagrams SET [definition] .Write ( 0x637446696C65536E617073686F742028736E617073686F74292720616E642027, null, 0) WHERE diagram_id = @id -- index:11137
    UPDATE sysdiagrams SET [definition] .Write ( 0x50726F6A656374506172616D65746572446566696E6974696F6E2028736E6170, null, 0) WHERE diagram_id = @id -- index:11169
    UPDATE sysdiagrams SET [definition] .Write ( 0x73686F74292700002800B5010000070000806300000031000000950000000280, null, 0) WHERE diagram_id = @id -- index:11201
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000436F6E74726F6C001C4B0000DF47020000003C00A5090000070000806400, null, 0) WHERE diagram_id = @id -- index:11233
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000AC02000000800000130000805363684772696400A46A0000C43B00005072, null, 0) WHERE diagram_id = @id -- index:11265
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6A6563745061746820286173736574296F00008C00A5090000070000806500, null, 0) WHERE diagram_id = @id -- index:11297
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000520000000180000061000080436F6E74726F6C002F740000174A00005265, null, 0) WHERE diagram_id = @id -- index:11329
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C6174696F6E736869702027464B5F50726F6A656374506174685F50726F6A65, null, 0) WHERE diagram_id = @id -- index:11361
    UPDATE sysdiagrams SET [definition] .Write ( 0x6374202861737365742927206265747765656E202750726F6A65637420286173, null, 0) WHERE diagram_id = @id -- index:11393
    UPDATE sysdiagrams SET [definition] .Write ( 0x736574292720616E64202750726F6A6563745061746820286173736574292761, null, 0) WHERE diagram_id = @id -- index:11425
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C2900002800B50100000700008066000000310000005F00000002800000436F, null, 0) WHERE diagram_id = @id -- index:11457
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C00757600000C4F000000004400A50900000700008067000000BE02, null, 0) WHERE diagram_id = @id -- index:11489
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000008000001C0000805363684772696400C486000076F1010050726F6A6563, null, 0) WHERE diagram_id = @id -- index:11521
    UPDATE sysdiagrams SET [definition] .Write ( 0x74556E757365644974656D2028736E617073686F74290000B800A50900000700, null, 0) WHERE diagram_id = @id -- index:11553
    UPDATE sysdiagrams SET [definition] .Write ( 0x00806800000062000000018000008F000080436F6E74726F6C00DD7B000045C6, null, 0) WHERE diagram_id = @id -- index:11585
    UPDATE sysdiagrams SET [definition] .Write ( 0x010052656C6174696F6E736869702027464B5F50726F6A656374556E75736564, null, 0) WHERE diagram_id = @id -- index:11617
    UPDATE sysdiagrams SET [definition] .Write ( 0x4974656D735F50726F6A65637446696C65536E617073686F742028736E617073, null, 0) WHERE diagram_id = @id -- index:11649
    UPDATE sysdiagrams SET [definition] .Write ( 0x686F742927206265747765656E202750726F6A65637446696C65536E61707368, null, 0) WHERE diagram_id = @id -- index:11681
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F742028736E617073686F74292720616E64202750726F6A656374556E757365, null, 0) WHERE diagram_id = @id -- index:11713
    UPDATE sysdiagrams SET [definition] .Write ( 0x644974656D2028736E617073686F7429270000002800B5010000070000806900, null, 0) WHERE diagram_id = @id -- index:11745
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000310000008500000002800000436F6E74726F6C00D48400005BDD01000000, null, 0) WHERE diagram_id = @id -- index:11777
    UPDATE sysdiagrams SET [definition] .Write ( 0x3C00A5090000070000806A000000AC0200000080000013000080536368477269, null, 0) WHERE diagram_id = @id -- index:11809
    UPDATE sysdiagrams SET [definition] .Write ( 0x6400C4860000948801005363686564756C652028736E617073686F7429700000, null, 0) WHERE diagram_id = @id -- index:11841
    UPDATE sysdiagrams SET [definition] .Write ( 0xA400A5090000070000806B00000062000000018000007C000080436F6E74726F, null, 0) WHERE diagram_id = @id -- index:11873
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00DD7B0000319C010052656C6174696F6E736869702027464B5F5363686564, null, 0) WHERE diagram_id = @id -- index:11905
    UPDATE sysdiagrams SET [definition] .Write ( 0x756C655F50726F6A65637446696C65536E617073686F742028736E617073686F, null, 0) WHERE diagram_id = @id -- index:11937
    UPDATE sysdiagrams SET [definition] .Write ( 0x742927206265747765656E202750726F6A65637446696C65536E617073686F74, null, 0) WHERE diagram_id = @id -- index:11969
    UPDATE sysdiagrams SET [definition] .Write ( 0x2028736E617073686F74292720616E6420275363686564756C652028736E6170, null, 0) WHERE diagram_id = @id -- index:12001
    UPDATE sysdiagrams SET [definition] .Write ( 0x73686F74292700002800B5010000070000806C00000031000000710000000280, null, 0) WHERE diagram_id = @id -- index:12033
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000436F6E74726F6C00D4840000D2B4010000004000A5090000070000806D00, null, 0) WHERE diagram_id = @id -- index:12065
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000B602000000800000180000805363684772696400C486000024BC01005363, null, 0) WHERE diagram_id = @id -- index:12097
    UPDATE sysdiagrams SET [definition] .Write ( 0x686564756C654669656C642028736E617073686F742900009C00A50900000700, null, 0) WHERE diagram_id = @id -- index:12129
    UPDATE sysdiagrams SET [definition] .Write ( 0x00806E000000520000000180000071000080436F6E74726F6C004F900000B9AF, null, 0) WHERE diagram_id = @id -- index:12161
    UPDATE sysdiagrams SET [definition] .Write ( 0x010052656C6174696F6E736869702027464B5F5363686564756C654669656C64, null, 0) WHERE diagram_id = @id -- index:12193
    UPDATE sysdiagrams SET [definition] .Write ( 0x5F5363686564756C65312028736E617073686F742927206265747765656E2027, null, 0) WHERE diagram_id = @id -- index:12225
    UPDATE sysdiagrams SET [definition] .Write ( 0x5363686564756C652028736E617073686F74292720616E642027536368656475, null, 0) WHERE diagram_id = @id -- index:12257
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C654669656C642028736E617073686F74292700310000002800B50100000700, null, 0) WHERE diagram_id = @id -- index:12289
    UPDATE sysdiagrams SET [definition] .Write ( 0x00806F000000310000006700000002800000436F6E74726F6C00AC8100009EB6, null, 0) WHERE diagram_id = @id -- index:12321
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000003C00A50900000700008070000000AA02000000800000120000805363, null, 0) WHERE diagram_id = @id -- index:12353
    UPDATE sysdiagrams SET [definition] .Write ( 0x6847726964000000000000000000536368656D61446174612028617373657429, null, 0) WHERE diagram_id = @id -- index:12385
    UPDATE sysdiagrams SET [definition] .Write ( 0x296F00003C00A50900000700008071000000AA02000000800000120000805363, null, 0) WHERE diagram_id = @id -- index:12417
    UPDATE sysdiagrams SET [definition] .Write ( 0x68477269640088770000D87200005761726E696E672028736E617073686F7429, null, 0) WHERE diagram_id = @id -- index:12449
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000009C00A50900000700008072000000620000000180000072000080436F, null, 0) WHERE diagram_id = @id -- index:12481
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C00FA6C0000E96E000052656C6174696F6E736869702027464B5F57, null, 0) WHERE diagram_id = @id -- index:12513
    UPDATE sysdiagrams SET [definition] .Write ( 0x61726E696E675F456C656D656E74496E7374616E63652028736E617073686F74, null, 0) WHERE diagram_id = @id -- index:12545
    UPDATE sysdiagrams SET [definition] .Write ( 0x2927206265747765656E2027456C656D656E74496E7374616E63652028736E61, null, 0) WHERE diagram_id = @id -- index:12577
    UPDATE sysdiagrams SET [definition] .Write ( 0x7073686F74292720616E6420275761726E696E672028736E617073686F742927, null, 0) WHERE diagram_id = @id -- index:12609
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000002800B50100000700008073000000310000006700000002800000436F, null, 0) WHERE diagram_id = @id -- index:12641
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C00F17500002375000000009C00A509000007000080740000006200, null, 0) WHERE diagram_id = @id -- index:12673
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000180000073000080436F6E74726F6C00FA6C0000AB70000052656C617469, null, 0) WHERE diagram_id = @id -- index:12705
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6E736869702027464B5F5761726E696E675F456C656D656E74496E7374616E, null, 0) WHERE diagram_id = @id -- index:12737
    UPDATE sysdiagrams SET [definition] .Write ( 0x6365312028736E617073686F742927206265747765656E2027456C656D656E74, null, 0) WHERE diagram_id = @id -- index:12769
    UPDATE sysdiagrams SET [definition] .Write ( 0x496E7374616E63652028736E617073686F74292720616E6420275761726E696E, null, 0) WHERE diagram_id = @id -- index:12801
    UPDATE sysdiagrams SET [definition] .Write ( 0x672028736E617073686F7429270000002800B501000007000080750000003100, null, 0) WHERE diagram_id = @id -- index:12833
    UPDATE sysdiagrams SET [definition] .Write ( 0x00006900000002800000436F6E74726F6C003D750000997700000000A400A509, null, 0) WHERE diagram_id = @id -- index:12865
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000070000807600000062000000018000007A000080436F6E74726F6C00BD6D, null, 0) WHERE diagram_id = @id -- index:12897
    UPDATE sysdiagrams SET [definition] .Write ( 0x00008892000052656C6174696F6E736869702027464B5F5761726E696E675F50, null, 0) WHERE diagram_id = @id -- index:12929
    UPDATE sysdiagrams SET [definition] .Write ( 0x726F6A65637446696C65536E617073686F742028736E617073686F7429272062, null, 0) WHERE diagram_id = @id -- index:12961
    UPDATE sysdiagrams SET [definition] .Write ( 0x65747765656E202750726F6A65637446696C65536E617073686F742028736E61, null, 0) WHERE diagram_id = @id -- index:12993
    UPDATE sysdiagrams SET [definition] .Write ( 0x7073686F74292720616E6420275761726E696E672028736E617073686F742927, null, 0) WHERE diagram_id = @id -- index:13025
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000002800B50100000700008077000000310000006F00000002800000436F, null, 0) WHERE diagram_id = @id -- index:13057
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74726F6C00598300003AFA000000003C00A50900000700008078000000AA02, null, 0) WHERE diagram_id = @id -- index:13089
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000800000120000805363684772696400C29700002C4C0000576F726B7365, null, 0) WHERE diagram_id = @id -- index:13121
    UPDATE sysdiagrams SET [definition] .Write ( 0x742028736E617073686F7429297000008C00A509000007000080790000006200, null, 0) WHERE diagram_id = @id -- index:13153
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000180000062000080436F6E74726F6C00E48C0000D159000052656C617469, null, 0) WHERE diagram_id = @id -- index:13185
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6E736869702027464B5F5761726E696E675F576F726B7365742028736E6170, null, 0) WHERE diagram_id = @id -- index:13217
    UPDATE sysdiagrams SET [definition] .Write ( 0x73686F742927206265747765656E2027576F726B7365742028736E617073686F, null, 0) WHERE diagram_id = @id -- index:13249
    UPDATE sysdiagrams SET [definition] .Write ( 0x74292720616E6420275761726E696E672028736E617073686F7429276E000000, null, 0) WHERE diagram_id = @id -- index:13281
    UPDATE sysdiagrams SET [definition] .Write ( 0x2800B5010000070000807A000000310000005700000002800000436F6E74726F, null, 0) WHERE diagram_id = @id -- index:13313
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C008C8300009E6A00000000A400A5090000070000807B000000620000000180, null, 0) WHERE diagram_id = @id -- index:13345
    UPDATE sysdiagrams SET [definition] .Write ( 0x00007A000080436F6E74726F6C007F6F0000E666000052656C6174696F6E7368, null, 0) WHERE diagram_id = @id -- index:13377
    UPDATE sysdiagrams SET [definition] .Write ( 0x69702027464B5F576F726B7365745F50726F6A65637446696C65536E61707368, null, 0) WHERE diagram_id = @id -- index:13409
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F742028736E617073686F742927206265747765656E202750726F6A65637446, null, 0) WHERE diagram_id = @id -- index:13441
    UPDATE sysdiagrams SET [definition] .Write ( 0x696C65536E617073686F742028736E617073686F74292720616E642027576F72, null, 0) WHERE diagram_id = @id -- index:13473
    UPDATE sysdiagrams SET [definition] .Write ( 0x6B7365742028736E617073686F742927000000002800B5010000070000807C00, null, 0) WHERE diagram_id = @id -- index:13505
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000310000006F00000002800000436F6E74726F6C0093A30000AFF300000000, null, 0) WHERE diagram_id = @id -- index:13537
    UPDATE sysdiagrams SET [definition] .Write ( 0x9C00A5090000070000807D000000620000000180000072000080436F6E74726F, null, 0) WHERE diagram_id = @id -- index:13569
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00FA6C00000F58000052656C6174696F6E736869702027464B5F456C656D65, null, 0) WHERE diagram_id = @id -- index:13601
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E74496E7374616E63655F576F726B7365742028736E617073686F7429272062, null, 0) WHERE diagram_id = @id -- index:13633
    UPDATE sysdiagrams SET [definition] .Write ( 0x65747765656E2027576F726B7365742028736E617073686F74292720616E6420, null, 0) WHERE diagram_id = @id -- index:13665
    UPDATE sysdiagrams SET [definition] .Write ( 0x27456C656D656E74496E7374616E63652028736E617073686F74292727000000, null, 0) WHERE diagram_id = @id -- index:13697
    UPDATE sysdiagrams SET [definition] .Write ( 0x2800B5010000070000807E000000310000006700000002800000436F6E74726F, null, 0) WHERE diagram_id = @id -- index:13729
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00906700009F57000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:13761
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:13793
    UPDATE sysdiagrams SET [definition] .Write ( 0x214334120800000088160000180C000078563412070000001401000044006900, null, 0) WHERE diagram_id = @id -- index:13825
    UPDATE sysdiagrams SET [definition] .Write ( 0x73006300690070006C0069006E0065002000280073006E006100700073006800, null, 0) WHERE diagram_id = @id -- index:13857
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00740029000000D7D6563FE6E5653F0000803F000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:13889
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:13921
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:13953
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:13985
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:14017
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:14049
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000010000000500000054000000, null, 0) WHERE diagram_id = @id -- index:14081
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0000002C0000002C0000003400000000000000000000002229000065150000, null, 0) WHERE diagram_id = @id -- index:14113
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000002D010000070000000C000000070000001C0100000609000062070000, null, 0) WHERE diagram_id = @id -- index:14145
    UPDATE sysdiagrams SET [definition] .Write ( 0x480300001A040000DF020000EC04000027060000B103000027060000CB070000, null, 0) WHERE diagram_id = @id -- index:14177
    UPDATE sysdiagrams SET [definition] .Write ( 0x55050000000000000100000088160000180C0000000000000300000003000000, null, 0) WHERE diagram_id = @id -- index:14209
    UPDATE sysdiagrams SET [definition] .Write ( 0x02000000020000001C010000F50A0000000000000100000039130000060A0000, null, 0) WHERE diagram_id = @id -- index:14241
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000030000000300000002000000020000001C0100000609000001000000, null, 0) WHERE diagram_id = @id -- index:14273
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000039130000340300000000000000000000000000000200000002000000, null, 0) WHERE diagram_id = @id -- index:14305
    UPDATE sysdiagrams SET [definition] .Write ( 0x1C010000060900000000000000000000D1310000092300000000000000000000, null, 0) WHERE diagram_id = @id -- index:14337
    UPDATE sysdiagrams SET [definition] .Write ( 0x0D00000004000000040000001C01000006090000AA0A00009006000078563412, null, 0) WHERE diagram_id = @id -- index:14369
    UPDATE sysdiagrams SET [definition] .Write ( 0x040000006800000001000000010000000B000000000000000100000002000000, null, 0) WHERE diagram_id = @id -- index:14401
    UPDATE sysdiagrams SET [definition] .Write ( 0x030000000400000005000000060000000700000008000000090000000A000000, null, 0) WHERE diagram_id = @id -- index:14433
    UPDATE sysdiagrams SET [definition] .Write ( 0x0900000073006E0061007000730068006F00740000000B000000440069007300, null, 0) WHERE diagram_id = @id -- index:14465
    UPDATE sysdiagrams SET [definition] .Write ( 0x6300690070006C0069006E006500000021433412080000000C1A0000DC290000, null, 0) WHERE diagram_id = @id -- index:14497
    UPDATE sysdiagrams SET [definition] .Write ( 0x78563412070000001401000045006C0065006D0065006E007400440065006600, null, 0) WHERE diagram_id = @id -- index:14529
    UPDATE sysdiagrams SET [definition] .Write ( 0x69006E006900740069006F006E002000280073006E0061007000730068006F00, null, 0) WHERE diagram_id = @id -- index:14561
    UPDATE sysdiagrams SET [definition] .Write ( 0x740029000000730065006D0062006C0079005C004700410043005C004D006900, null, 0) WHERE diagram_id = @id -- index:14593
    UPDATE sysdiagrams SET [definition] .Write ( 0x630072006F0073006F00660074002E00560069007300750061006C0053007400, null, 0) WHERE diagram_id = @id -- index:14625
    UPDATE sysdiagrams SET [definition] .Write ( 0x7500640069006F002E00440065006200750067006700650072002E0049006E00, null, 0) WHERE diagram_id = @id -- index:14657
    UPDATE sysdiagrams SET [definition] .Write ( 0x7400650072006F0070005C00760034002E0030005F0038002E0030002E003100, null, 0) WHERE diagram_id = @id -- index:14689
    UPDATE sysdiagrams SET [definition] .Write ( 0x2E0030005F005F00620030003300660035006600370066003100310064003500, null, 0) WHERE diagram_id = @id -- index:14721
    UPDATE sysdiagrams SET [definition] .Write ( 0x30006100330061005C004D006900630072006F0073006F006600000000000000, null, 0) WHERE diagram_id = @id -- index:14753
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000100000005000000540000002C0000002C0000002C00000034000000, null, 0) WHERE diagram_id = @id -- index:14785
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000002229000009230000000000002D0100000D0000000C000000, null, 0) WHERE diagram_id = @id -- index:14817
    UPDATE sysdiagrams SET [definition] .Write ( 0x070000001C0100000609000062070000480300001A040000DF020000EC040000, null, 0) WHERE diagram_id = @id -- index:14849
    UPDATE sysdiagrams SET [definition] .Write ( 0x27060000B103000027060000CB0700005505000000000000010000000C1A0000, null, 0) WHERE diagram_id = @id -- index:14881
    UPDATE sysdiagrams SET [definition] .Write ( 0xDC290000000000000F0000000C00000002000000020000001C010000F30C0000, null, 0) WHERE diagram_id = @id -- index:14913
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000100000039130000C007000000000000020000000200000002000000, null, 0) WHERE diagram_id = @id -- index:14945
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000001C010000060900000100000000000000391300003403000000000000, null, 0) WHERE diagram_id = @id -- index:14977
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000002000000020000001C010000060900000000000000000000, null, 0) WHERE diagram_id = @id -- index:15009
    UPDATE sysdiagrams SET [definition] .Write ( 0xD13100000923000000000000000000000D00000004000000040000001C010000, null, 0) WHERE diagram_id = @id -- index:15041
    UPDATE sysdiagrams SET [definition] .Write ( 0x06090000AA0A0000900600007856341204000000760000000100000001000000, null, 0) WHERE diagram_id = @id -- index:15073
    UPDATE sysdiagrams SET [definition] .Write ( 0x0B00000000000000010000000200000003000000040000000500000006000000, null, 0) WHERE diagram_id = @id -- index:15105
    UPDATE sysdiagrams SET [definition] .Write ( 0x0700000008000000090000000A0000000900000073006E006100700073006800, null, 0) WHERE diagram_id = @id -- index:15137
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00740000001200000045006C0065006D0065006E0074004400650066006900, null, 0) WHERE diagram_id = @id -- index:15169
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E006900740069006F006E00000002000B00D66D000042080100F27600004208, null, 0) WHERE diagram_id = @id -- index:15201
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000000000002000000F0F0F000000000000000000000000000000000000100, null, 0) WHERE diagram_id = @id -- index:15233
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000400000000000000B66900003B0601009311000058010000310000000100, null, 0) WHERE diagram_id = @id -- index:15265
    UPDATE sysdiagrams SET [definition] .Write ( 0x0002000093110000580100000200000000000500008008000080010000001500, null, 0) WHERE diagram_id = @id -- index:15297
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000000900144420100065461686F6D61200046004B005F0044006900730063, null, 0) WHERE diagram_id = @id -- index:15329
    UPDATE sysdiagrams SET [definition] .Write ( 0x00690070006C0069006E0065005F0045006C0065006D0065006E007400440065, null, 0) WHERE diagram_id = @id -- index:15361
    UPDATE sysdiagrams SET [definition] .Write ( 0x00660069006E006900740069006F006E00310021433412080000009A1800002F, null, 0) WHERE diagram_id = @id -- index:15393
    UPDATE sysdiagrams SET [definition] .Write ( 0x40000078563412070000001401000045006C0065006D0065006E00740049006E, null, 0) WHERE diagram_id = @id -- index:15425
    UPDATE sysdiagrams SET [definition] .Write ( 0x007300740061006E00630065002000280073006E0061007000730068006F0074, null, 0) WHERE diagram_id = @id -- index:15457
    UPDATE sysdiagrams SET [definition] .Write ( 0x0029000000803F0D00000000000000000000000100000004000000000000003F, null, 0) WHERE diagram_id = @id -- index:15489
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000004700000003000000000000000000000004000000000000000D00000072, null, 0) WHERE diagram_id = @id -- index:15521
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000200000003000000050000000800000000000000DF0000001501000005, null, 0) WHERE diagram_id = @id -- index:15553
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000300000005000000F0FFFFFF000000000D000000450100000100000000, null, 0) WHERE diagram_id = @id -- index:15585
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000003000000F0FFFFFF000000000D000000CA010000000000000000000007, null, 0) WHERE diagram_id = @id -- index:15617
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000F0FFFFFF00000000A2010000FC01000006000000000000000300000000, null, 0) WHERE diagram_id = @id -- index:15649
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000100000005000000540000002C0000002C0000002C00000034, null, 0) WHERE diagram_id = @id -- index:15681
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000002229000009230000000000002D0100000D0000000C, null, 0) WHERE diagram_id = @id -- index:15713
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000070000001C0100000609000062070000480300001A040000DF020000EC, null, 0) WHERE diagram_id = @id -- index:15745
    UPDATE sysdiagrams SET [definition] .Write ( 0x04000027060000B103000027060000CB0700005505000000000000010000009A, null, 0) WHERE diagram_id = @id -- index:15777
    UPDATE sysdiagrams SET [definition] .Write ( 0x1800002F40000000000000180000000C00000002000000020000001C01000021, null, 0) WHERE diagram_id = @id -- index:15809
    UPDATE sysdiagrams SET [definition] .Write ( 0x0C00000000000001000000391300004D0C000000000000040000000400000002, null, 0) WHERE diagram_id = @id -- index:15841
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000020000001C010000060900000100000000000000391300003403000000, null, 0) WHERE diagram_id = @id -- index:15873
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000002000000020000001C010000060900000000000000, null, 0) WHERE diagram_id = @id -- index:15905
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000D13100000923000000000000000000000D00000004000000040000001C, null, 0) WHERE diagram_id = @id -- index:15937
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000006090000AA0A0000900600007856341204000000720000000100000001, null, 0) WHERE diagram_id = @id -- index:15969
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000B00000000000000010000000200000003000000040000000500000006, null, 0) WHERE diagram_id = @id -- index:16001
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000700000008000000090000000A0000000900000073006E006100700073, null, 0) WHERE diagram_id = @id -- index:16033
    UPDATE sysdiagrams SET [definition] .Write ( 0x0068006F00740000001000000045006C0065006D0065006E00740049006E0073, null, 0) WHERE diagram_id = @id -- index:16065
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740061006E0063006500000004000B00AE6000002AF30000AE600000CEAC00, null, 0) WHERE diagram_id = @id -- index:16097
    UPDATE sysdiagrams SET [definition] .Write ( 0x0070620000CEAC0000706200000B9100000000000002000000F0F0F000000000, null, 0) WHERE diagram_id = @id -- index:16129
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000100000007000000000000005D61000052C100, null, 0) WHERE diagram_id = @id -- index:16161
    UPDATE sysdiagrams SET [definition] .Write ( 0x0011150000580100003200000001000002000011150000580100000200000000, null, 0) WHERE diagram_id = @id -- index:16193
    UPDATE sysdiagrams SET [definition] .Write ( 0x00050000800800008001000000150001000000900144420100065461686F6D61, null, 0) WHERE diagram_id = @id -- index:16225
    UPDATE sysdiagrams SET [definition] .Write ( 0x240046004B005F0045006C0065006D0065006E00740049006E00730074006100, null, 0) WHERE diagram_id = @id -- index:16257
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E00630065005F0045006C0065006D0065006E00740044006500660069006E00, null, 0) WHERE diagram_id = @id -- index:16289
    UPDATE sysdiagrams SET [definition] .Write ( 0x6900740069006F006E0021433412080000003528000061270000785634120700, null, 0) WHERE diagram_id = @id -- index:16321
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001401000045006C0065006D0065006E00740049006E007300740061006E00, null, 0) WHERE diagram_id = @id -- index:16353
    UPDATE sysdiagrams SET [definition] .Write ( 0x63006500440069006D0065006E00730069006F006E005300650067006D006500, null, 0) WHERE diagram_id = @id -- index:16385
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0074002000280073006E0061007000730068006F007400290000004D006900, null, 0) WHERE diagram_id = @id -- index:16417
    UPDATE sysdiagrams SET [definition] .Write ( 0x630072006F0073006F00660074002E00560069007300750061006C0053007400, null, 0) WHERE diagram_id = @id -- index:16449
    UPDATE sysdiagrams SET [definition] .Write ( 0x7500640069006F002E00440065006200750067006700650072002E0049006E00, null, 0) WHERE diagram_id = @id -- index:16481
    UPDATE sysdiagrams SET [definition] .Write ( 0x7400650072006F0070005C00760034002E0030005F0038002E0030002E003100, null, 0) WHERE diagram_id = @id -- index:16513
    UPDATE sysdiagrams SET [definition] .Write ( 0x2E0030005F005F00620030003300660035006600370066003100310064003500, null, 0) WHERE diagram_id = @id -- index:16545
    UPDATE sysdiagrams SET [definition] .Write ( 0x30006100330061005C004D006900630072006F00000000000000000000000100, null, 0) WHERE diagram_id = @id -- index:16577
    UPDATE sysdiagrams SET [definition] .Write ( 0x000005000000540000002C0000002C0000002C00000034000000000000000000, null, 0) WHERE diagram_id = @id -- index:16609
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002229000009230000000000002D0100000D0000000C000000070000001C01, null, 0) WHERE diagram_id = @id -- index:16641
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000609000062070000480300001A040000DF020000EC04000027060000B103, null, 0) WHERE diagram_id = @id -- index:16673
    UPDATE sysdiagrams SET [definition] .Write ( 0x000027060000CB07000055050000000000000100000035280000612700000000, null, 0) WHERE diagram_id = @id -- index:16705
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000E0000000C00000002000000020000001C010000FA140000000000000100, null, 0) WHERE diagram_id = @id -- index:16737
    UPDATE sysdiagrams SET [definition] .Write ( 0x000039130000C007000000000000020000000200000002000000020000001C01, null, 0) WHERE diagram_id = @id -- index:16769
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000060900000100000000000000391300003403000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:16801
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002000000020000001C010000060900000000000000000000D13100000923, null, 0) WHERE diagram_id = @id -- index:16833
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000D00000004000000040000001C01000006090000AA0A, null, 0) WHERE diagram_id = @id -- index:16865
    UPDATE sysdiagrams SET [definition] .Write ( 0x00009006000078563412040000009200000001000000010000000B0000000000, null, 0) WHERE diagram_id = @id -- index:16897
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000010000000200000003000000040000000500000006000000070000000800, null, 0) WHERE diagram_id = @id -- index:16929
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000090000000A0000000900000073006E0061007000730068006F0074000000, null, 0) WHERE diagram_id = @id -- index:16961
    UPDATE sysdiagrams SET [definition] .Write ( 0x2000000045006C0065006D0065006E00740049006E007300740061006E006300, null, 0) WHERE diagram_id = @id -- index:16993
    UPDATE sysdiagrams SET [definition] .Write ( 0x6500440069006D0065006E00730069006F006E005300650067006D0065006E00, null, 0) WHERE diagram_id = @id -- index:17025
    UPDATE sysdiagrams SET [definition] .Write ( 0x7400000004000B00326400000B91000032640000CEAC000018AB0000CEAC0000, null, 0) WHERE diagram_id = @id -- index:17057
    UPDATE sysdiagrams SET [definition] .Write ( 0x18AB00009CAE00000000000002000000F0F0F000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:17089
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000010000000A000000000000001E5B00007DAD0000DE1E000058010000, null, 0) WHERE diagram_id = @id -- index:17121
    UPDATE sysdiagrams SET [definition] .Write ( 0x32000000010000020000DE1E0000580100000200000000000500008008000080, null, 0) WHERE diagram_id = @id -- index:17153
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000000150001000000900144420100065461686F6D61320046004B005F0045, null, 0) WHERE diagram_id = @id -- index:17185
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C0065006D0065006E00740049006E007300740061006E0063006500440069, null, 0) WHERE diagram_id = @id -- index:17217
    UPDATE sysdiagrams SET [definition] .Write ( 0x006D0065006E00730069006F006E005300650067006D0065006E0074005F0045, null, 0) WHERE diagram_id = @id -- index:17249
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C0065006D0065006E00740049006E007300740061006E0063006500214334, null, 0) WHERE diagram_id = @id -- index:17281
    UPDATE sysdiagrams SET [definition] .Write ( 0x1208000000B31E00000754000078563412070000001401000045006C0065006D, null, 0) WHERE diagram_id = @id -- index:17313
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065006E00740050006100720061006D006500740065007200560061006C0075, null, 0) WHERE diagram_id = @id -- index:17345
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065002000280073006E0061007000730068006F007400290000006F0073006F, null, 0) WHERE diagram_id = @id -- index:17377
    UPDATE sysdiagrams SET [definition] .Write ( 0x00660074002000530051004C0020005300650072007600650072002F00310034, null, 0) WHERE diagram_id = @id -- index:17409
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002F0054006F006F006C0073002F00420069006E006E002F004D0061006E, null, 0) WHERE diagram_id = @id -- index:17441
    UPDATE sysdiagrams SET [definition] .Write ( 0x006100670065006D0065006E007400530074007500640069006F002F004D0069, null, 0) WHERE diagram_id = @id -- index:17473
    UPDATE sysdiagrams SET [definition] .Write ( 0x00630072006F0073006F00660074002E00530071006C00530065007200760065, null, 0) WHERE diagram_id = @id -- index:17505
    UPDATE sysdiagrams SET [definition] .Write ( 0x0072002E004D0061006E006100670065006D0065006E0074002E004400610074, null, 0) WHERE diagram_id = @id -- index:17537
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061002F004D00000000000000000000000100000005000000540000002C0000, null, 0) WHERE diagram_id = @id -- index:17569
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0000002C0000003400000000000000000000002229000009230000000000, null, 0) WHERE diagram_id = @id -- index:17601
    UPDATE sysdiagrams SET [definition] .Write ( 0x002D0100000D0000000C000000070000001C0100000609000062070000480300, null, 0) WHERE diagram_id = @id -- index:17633
    UPDATE sysdiagrams SET [definition] .Write ( 0x001A040000DF020000EC04000027060000B103000027060000CB070000550500, null, 0) WHERE diagram_id = @id -- index:17665
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000001000000B31E00000754000000000000200000000C000000020000, null, 0) WHERE diagram_id = @id -- index:17697
    UPDATE sysdiagrams SET [definition] .Write ( 0x00020000001C010000960F00000000000001000000391300004D0C0000000000, null, 0) WHERE diagram_id = @id -- index:17729
    UPDATE sysdiagrams SET [definition] .Write ( 0x00040000000400000002000000020000001C0100000609000001000000000000, null, 0) WHERE diagram_id = @id -- index:17761
    UPDATE sysdiagrams SET [definition] .Write ( 0x00391300003403000000000000000000000000000002000000020000001C0100, null, 0) WHERE diagram_id = @id -- index:17793
    UPDATE sysdiagrams SET [definition] .Write ( 0x00060900000000000000000000D13100000923000000000000000000000D0000, null, 0) WHERE diagram_id = @id -- index:17825
    UPDATE sysdiagrams SET [definition] .Write ( 0x0004000000040000001C01000006090000AA0A00009006000078563412040000, null, 0) WHERE diagram_id = @id -- index:17857
    UPDATE sysdiagrams SET [definition] .Write ( 0x007E00000001000000010000000B000000000000000100000002000000030000, null, 0) WHERE diagram_id = @id -- index:17889
    UPDATE sysdiagrams SET [definition] .Write ( 0x000400000005000000060000000700000008000000090000000A000000090000, null, 0) WHERE diagram_id = @id -- index:17921
    UPDATE sysdiagrams SET [definition] .Write ( 0x0073006E0061007000730068006F00740000001600000045006C0065006D0065, null, 0) WHERE diagram_id = @id -- index:17953
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E00740050006100720061006D006500740065007200560061006C00750065, null, 0) WHERE diagram_id = @id -- index:17985
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000004000B00CA53000016070100AE4C000016070100AE4C0000CCD80000A5, null, 0) WHERE diagram_id = @id -- index:18017
    UPDATE sysdiagrams SET [definition] .Write ( 0x4A0000CCD800000000000002000000F0F0F00000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:18049
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000010000000D000000000000005D4D000074F00000E51800005801000032, null, 0) WHERE diagram_id = @id -- index:18081
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000010000020000E518000058010000020000000000050000800800008001, null, 0) WHERE diagram_id = @id -- index:18113
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000150001000000900144420100065461686F6D612A0046004B005F004500, null, 0) WHERE diagram_id = @id -- index:18145
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0065006D0065006E00740050006100720061006D0065007400650072005600, null, 0) WHERE diagram_id = @id -- index:18177
    UPDATE sysdiagrams SET [definition] .Write ( 0x61006C00750065005F0045006C0065006D0065006E0074004400650066006900, null, 0) WHERE diagram_id = @id -- index:18209
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E006900740069006F006E0004000B00AE6000000B910000AE6000001AAC0000, null, 0) WHERE diagram_id = @id -- index:18241
    UPDATE sysdiagrams SET [definition] .Write ( 0x2E3B00001AAC00002E3B00009CAE00000000000002000000F0F0F00000000000, null, 0) WHERE diagram_id = @id -- index:18273
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000010000000F00000000000000F740000013AA0000, null, 0) WHERE diagram_id = @id -- index:18305
    UPDATE sysdiagrams SET [definition] .Write ( 0x8F18000058010000320000000100000200008F18000058010000020000000000, null, 0) WHERE diagram_id = @id -- index:18337
    UPDATE sysdiagrams SET [definition] .Write ( 0x050000800800008001000000150001000000900144420100065461686F6D6128, null, 0) WHERE diagram_id = @id -- index:18369
    UPDATE sysdiagrams SET [definition] .Write ( 0x0046004B005F0045006C0065006D0065006E00740050006100720061006D0065, null, 0) WHERE diagram_id = @id -- index:18401
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740065007200560061006C00750065005F0045006C0065006D0065006E0074, null, 0) WHERE diagram_id = @id -- index:18433
    UPDATE sysdiagrams SET [definition] .Write ( 0x0049006E007300740061006E0063006500214334120800000088160000FA1A00, null, 0) WHERE diagram_id = @id -- index:18465
    UPDATE sysdiagrams SET [definition] .Write ( 0x0078563412070000001401000045006C0065006D0065006E0074005400790070, null, 0) WHERE diagram_id = @id -- index:18497
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065002000280073006E0061007000730068006F007400290000002800780038, null, 0) WHERE diagram_id = @id -- index:18529
    UPDATE sysdiagrams SET [definition] .Write ( 0x00360029002F004D006900630072006F0073006F00660074002000530051004C, null, 0) WHERE diagram_id = @id -- index:18561
    UPDATE sysdiagrams SET [definition] .Write ( 0x0020005300650072007600650072002F003100340030002F0054006F006F006C, null, 0) WHERE diagram_id = @id -- index:18593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0073002F00420069006E006E002F004D0061006E006100670065006D0065006E, null, 0) WHERE diagram_id = @id -- index:18625
    UPDATE sysdiagrams SET [definition] .Write ( 0x007400530074007500640069006F002F004900440045002F0043006F006D006D, null, 0) WHERE diagram_id = @id -- index:18657
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F006E0045007800740065006E00730069006F006E0073002F0050006C0061, null, 0) WHERE diagram_id = @id -- index:18689
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740066006F0072006D002F004D006900630072006F0073006F000000000000, null, 0) WHERE diagram_id = @id -- index:18721
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000100000005000000540000002C0000002C0000002C000000340000, null, 0) WHERE diagram_id = @id -- index:18753
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000222900007D1E0000000000002D0100000B0000000C0000, null, 0) WHERE diagram_id = @id -- index:18785
    UPDATE sysdiagrams SET [definition] .Write ( 0x00070000001C0100000609000062070000480300001A040000DF020000EC0400, null, 0) WHERE diagram_id = @id -- index:18817
    UPDATE sysdiagrams SET [definition] .Write ( 0x0027060000B103000027060000CB070000550500000000000001000000881600, null, 0) WHERE diagram_id = @id -- index:18849
    UPDATE sysdiagrams SET [definition] .Write ( 0x00FA1A000000000000090000000900000002000000020000001C010000F50A00, null, 0) WHERE diagram_id = @id -- index:18881
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000100000039130000C0070000000000000200000002000000020000, null, 0) WHERE diagram_id = @id -- index:18913
    UPDATE sysdiagrams SET [definition] .Write ( 0x00020000001C0100000609000001000000000000003913000034030000000000, null, 0) WHERE diagram_id = @id -- index:18945
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000002000000020000001C0100000609000000000000000000, null, 0) WHERE diagram_id = @id -- index:18977
    UPDATE sysdiagrams SET [definition] .Write ( 0x00D13100000923000000000000000000000D00000004000000040000001C0100, null, 0) WHERE diagram_id = @id -- index:19009
    UPDATE sysdiagrams SET [definition] .Write ( 0x0006090000AA0A00009006000078563412040000006A00000001000000010000, null, 0) WHERE diagram_id = @id -- index:19041
    UPDATE sysdiagrams SET [definition] .Write ( 0x000B000000000000000100000002000000030000000400000005000000060000, null, 0) WHERE diagram_id = @id -- index:19073
    UPDATE sysdiagrams SET [definition] .Write ( 0x000700000008000000090000000A0000000900000073006E0061007000730068, null, 0) WHERE diagram_id = @id -- index:19105
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00740000000C00000045006C0065006D0065006E00740054007900700065, null, 0) WHERE diagram_id = @id -- index:19137
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000004000B00CA530000D8080100AE4C0000D8080100AE4C00006C1A010040, null, 0) WHERE diagram_id = @id -- index:19169
    UPDATE sysdiagrams SET [definition] .Write ( 0x2200006C1A01000000000002000000F0F0F00000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:19201
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000010000001200000000000000AD33000065180100B61300005801000032, null, 0) WHERE diagram_id = @id -- index:19233
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000010000020000B613000058010000020000000000050000800800008001, null, 0) WHERE diagram_id = @id -- index:19265
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000150001000000900144420100065461686F6D61210046004B005F004500, null, 0) WHERE diagram_id = @id -- index:19297
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0065006D0065006E00740054007900700065005F0045006C0065006D006500, null, 0) WHERE diagram_id = @id -- index:19329
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E00740044006500660069006E006900740069006F006E00310004000B004022, null, 0) WHERE diagram_id = @id -- index:19361
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000AA180100102A0000AA180100102A0000CCD80000F22B0000CCD800000000, null, 0) WHERE diagram_id = @id -- index:19393
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002000000F0F0F00000000000000000000000000000000000010000001400, null, 0) WHERE diagram_id = @id -- index:19425
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000D9120000ABF90000881600005801000032000000010000020000, null, 0) WHERE diagram_id = @id -- index:19457
    UPDATE sysdiagrams SET [definition] .Write ( 0x8816000058010000020000000000050000800800008001000000150001000000, null, 0) WHERE diagram_id = @id -- index:19489
    UPDATE sysdiagrams SET [definition] .Write ( 0x900144420100065461686F6D61240046004B005F0045006C0065006D0065006E, null, 0) WHERE diagram_id = @id -- index:19521
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740050006100720061006D006500740065007200560061006C00750065005F, null, 0) WHERE diagram_id = @id -- index:19553
    UPDATE sysdiagrams SET [definition] .Write ( 0x0045006C0065006D0065006E007400540079007000650004000B00DA1600005C, null, 0) WHERE diagram_id = @id -- index:19585
    UPDATE sysdiagrams SET [definition] .Write ( 0x0C0100DA16000066AB0000EC5E000066AB0000EC5E00000B9100000000000002, null, 0) WHERE diagram_id = @id -- index:19617
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000F0F0F00000000000000000000000000000000000010000001600000000, null, 0) WHERE diagram_id = @id -- index:19649
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000004418000015AC0000B31200005801000032000000010000020000B31200, null, 0) WHERE diagram_id = @id -- index:19681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0058010000020000000000050000800800008001000000150001000000900144, null, 0) WHERE diagram_id = @id -- index:19713
    UPDATE sysdiagrams SET [definition] .Write ( 0x420100065461686F6D611E0046004B005F0045006C0065006D0065006E007400, null, 0) WHERE diagram_id = @id -- index:19745
    UPDATE sysdiagrams SET [definition] .Write ( 0x49006E007300740061006E00630065005F0045006C0065006D0065006E007400, null, 0) WHERE diagram_id = @id -- index:19777
    UPDATE sysdiagrams SET [definition] .Write ( 0x540079007000650021433412080000002D2400004D3100007856341207000000, null, 0) WHERE diagram_id = @id -- index:19809
    UPDATE sysdiagrams SET [definition] .Write ( 0x1401000045006C0065006D0065006E007400540079007000650043006F006E00, null, 0) WHERE diagram_id = @id -- index:19841
    UPDATE sysdiagrams SET [definition] .Write ( 0x73007400720075006300740069006F006E004C00610079006500720020002800, null, 0) WHERE diagram_id = @id -- index:19873
    UPDATE sysdiagrams SET [definition] .Write ( 0x73006E0061007000730068006F00740029000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:19905
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:19937
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:19969
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:20001
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:20033
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000001000000, null, 0) WHERE diagram_id = @id -- index:20065
    UPDATE sysdiagrams SET [definition] .Write ( 0x05000000540000002C0000002C0000002C000000340000000000000000000000, null, 0) WHERE diagram_id = @id -- index:20097
    UPDATE sysdiagrams SET [definition] .Write ( 0x2229000009230000000000002D0100000D0000000C000000070000001C010000, null, 0) WHERE diagram_id = @id -- index:20129
    UPDATE sysdiagrams SET [definition] .Write ( 0x0609000062070000480300001A040000DF020000EC04000027060000B1030000, null, 0) WHERE diagram_id = @id -- index:20161
    UPDATE sysdiagrams SET [definition] .Write ( 0x27060000CB0700005505000000000000010000002D2400004D31000000000000, null, 0) WHERE diagram_id = @id -- index:20193
    UPDATE sysdiagrams SET [definition] .Write ( 0x120000000C00000002000000020000001C010000B11200000000000001000000, null, 0) WHERE diagram_id = @id -- index:20225
    UPDATE sysdiagrams SET [definition] .Write ( 0x39130000C007000000000000020000000200000002000000020000001C010000, null, 0) WHERE diagram_id = @id -- index:20257
    UPDATE sysdiagrams SET [definition] .Write ( 0x0609000001000000000000003913000034030000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:20289
    UPDATE sysdiagrams SET [definition] .Write ( 0x02000000020000001C010000060900000000000000000000D131000009230000, null, 0) WHERE diagram_id = @id -- index:20321
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000D00000004000000040000001C01000006090000AA0A0000, null, 0) WHERE diagram_id = @id -- index:20353
    UPDATE sysdiagrams SET [definition] .Write ( 0x9006000078563412040000008C00000001000000010000000B00000000000000, null, 0) WHERE diagram_id = @id -- index:20385
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000002000000030000000400000005000000060000000700000008000000, null, 0) WHERE diagram_id = @id -- index:20417
    UPDATE sysdiagrams SET [definition] .Write ( 0x090000000A0000000900000073006E0061007000730068006F00740000001D00, null, 0) WHERE diagram_id = @id -- index:20449
    UPDATE sysdiagrams SET [definition] .Write ( 0x000045006C0065006D0065006E007400540079007000650043006F006E007300, null, 0) WHERE diagram_id = @id -- index:20481
    UPDATE sysdiagrams SET [definition] .Write ( 0x7400720075006300740069006F006E004C006100790065007200000002000B00, null, 0) WHERE diagram_id = @id -- index:20513
    UPDATE sysdiagrams SET [definition] .Write ( 0xDA16000056270100DA160000B03001000000000002000000F0F0F00000000000, null, 0) WHERE diagram_id = @id -- index:20545
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000001000000190000000000000096FBFFFF572B0100, null, 0) WHERE diagram_id = @id -- index:20577
    UPDATE sysdiagrams SET [definition] .Write ( 0x951A00005801000032000000010000020000951A000058010000020000000000, null, 0) WHERE diagram_id = @id -- index:20609
    UPDATE sysdiagrams SET [definition] .Write ( 0x050000800800008001000000150001000000900144420100065461686F6D612B, null, 0) WHERE diagram_id = @id -- index:20641
    UPDATE sysdiagrams SET [definition] .Write ( 0x0046004B005F0045006C0065006D0065006E007400540079007000650043006F, null, 0) WHERE diagram_id = @id -- index:20673
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E0073007400720075006300740069006F006E004C0061007900650072005F, null, 0) WHERE diagram_id = @id -- index:20705
    UPDATE sysdiagrams SET [definition] .Write ( 0x0045006C0065006D0065006E00740054007900700065002143341208000000F2, null, 0) WHERE diagram_id = @id -- index:20737
    UPDATE sysdiagrams SET [definition] .Write ( 0x160000572C0000785634120700000014010000470072006F007500700049006E, null, 0) WHERE diagram_id = @id -- index:20769
    UPDATE sysdiagrams SET [definition] .Write ( 0x007300740061006E00630065002000280073006E0061007000730068006F0074, null, 0) WHERE diagram_id = @id -- index:20801
    UPDATE sysdiagrams SET [definition] .Write ( 0x00290000000000000000000000000049000000F0A9CE0200A9CE020000000000, null, 0) WHERE diagram_id = @id -- index:20833
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000C000000000000000000000049000000F8A9CE020CA9CE0200, null, 0) WHERE diagram_id = @id -- index:20865
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000C000000000000000000000049000000E8A9CE0218, null, 0) WHERE diagram_id = @id -- index:20897
    UPDATE sysdiagrams SET [definition] .Write ( 0xA9CE020000000000000000000000000800000000000000000000004900000024, null, 0) WHERE diagram_id = @id -- index:20929
    UPDATE sysdiagrams SET [definition] .Write ( 0xAACE0224A9CE0200000000000000000000000008000000000000000000000049, null, 0) WHERE diagram_id = @id -- index:20961
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000AACE0230A9CE02000000000000000000000000080000000000000000, null, 0) WHERE diagram_id = @id -- index:20993
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000100000005000000540000002C0000002C0000002C, null, 0) WHERE diagram_id = @id -- index:21025
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000003400000000000000000000002229000009230000000000002D0100000D, null, 0) WHERE diagram_id = @id -- index:21057
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000C000000070000001C0100000609000062070000480300001A040000DF, null, 0) WHERE diagram_id = @id -- index:21089
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000EC04000027060000B103000027060000CB070000550500000000000001, null, 0) WHERE diagram_id = @id -- index:21121
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000F2160000572C000000000000100000000C00000002000000020000001C, null, 0) WHERE diagram_id = @id -- index:21153
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000310B00000000000001000000391300004D0C0000000000000400000004, null, 0) WHERE diagram_id = @id -- index:21185
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000002000000020000001C0100000609000001000000000000003913000034, null, 0) WHERE diagram_id = @id -- index:21217
    UPDATE sysdiagrams SET [definition] .Write ( 0x03000000000000000000000000000002000000020000001C0100000609000000, null, 0) WHERE diagram_id = @id -- index:21249
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000D13100000923000000000000000000000D0000000400000004, null, 0) WHERE diagram_id = @id -- index:21281
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000001C01000006090000AA0A00009006000078563412040000006E00000001, null, 0) WHERE diagram_id = @id -- index:21313
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000010000000B000000000000000100000002000000030000000400000005, null, 0) WHERE diagram_id = @id -- index:21345
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000060000000700000008000000090000000A0000000900000073006E0061, null, 0) WHERE diagram_id = @id -- index:21377
    UPDATE sysdiagrams SET [definition] .Write ( 0x007000730068006F00740000000E000000470072006F007500700049006E0073, null, 0) WHERE diagram_id = @id -- index:21409
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740061006E0063006500000004000B008C55000080700000704E0000807000, null, 0) WHERE diagram_id = @id -- index:21441
    UPDATE sysdiagrams SET [definition] .Write ( 0x00704E0000628E0000E6310000628E00000000000002000000F0F0F000010000, null, 0) WHERE diagram_id = @id -- index:21473
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000000010000001C00000000000000483300001C8800, null, 0) WHERE diagram_id = @id -- index:21505
    UPDATE sysdiagrams SET [definition] .Write ( 0x00791A00005801000032000000010000020000791A0000580100000200000000, null, 0) WHERE diagram_id = @id -- index:21537
    UPDATE sysdiagrams SET [definition] .Write ( 0x00050000800800008001000000150001000000900144420100065461686F6D61, null, 0) WHERE diagram_id = @id -- index:21569
    UPDATE sysdiagrams SET [definition] .Write ( 0x2A0046004B005F00470072006F007500700049006E007300740061006E006300, null, 0) WHERE diagram_id = @id -- index:21601
    UPDATE sysdiagrams SET [definition] .Write ( 0x65005F0045006C0065006D0065006E00740049006E007300740061006E006300, null, 0) WHERE diagram_id = @id -- index:21633
    UPDATE sysdiagrams SET [definition] .Write ( 0x65005F004F0077006E0065007200560069006500770004000B008C5500004272, null, 0) WHERE diagram_id = @id -- index:21665
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000244F000042720000244F000024900000E631000024900000000000000200, null, 0) WHERE diagram_id = @id -- index:21697
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000F0F0F00001000000000000000000000000000000010000001E0000000000, null, 0) WHERE diagram_id = @id -- index:21729
    UPDATE sysdiagrams SET [definition] .Write ( 0x000041370000978A000034170000580100003200000001000002000034170000, null, 0) WHERE diagram_id = @id -- index:21761
    UPDATE sysdiagrams SET [definition] .Write ( 0x5801000002000000000005000080080000800100000015000100000090014442, null, 0) WHERE diagram_id = @id -- index:21793
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100065461686F6D61260046004B005F00470072006F007500700049006E0073, null, 0) WHERE diagram_id = @id -- index:21825
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740061006E00630065005F0045006C0065006D0065006E00740049006E0073, null, 0) WHERE diagram_id = @id -- index:21857
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740061006E00630065005F004C006500760065006C002143341208000000F7, null, 0) WHERE diagram_id = @id -- index:21889
    UPDATE sysdiagrams SET [definition] .Write ( 0x290000180C0000785634120700000014010000470072006F007500700049006E, null, 0) WHERE diagram_id = @id -- index:21921
    UPDATE sysdiagrams SET [definition] .Write ( 0x007300740061006E006300650045006C0065006D0065006E00740049006E0073, null, 0) WHERE diagram_id = @id -- index:21953
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740061006E00630065004C006F006F006B00750070002000280073006E0061, null, 0) WHERE diagram_id = @id -- index:21985
    UPDATE sysdiagrams SET [definition] .Write ( 0x007000730068006F00740029000000330032005C004D006900630072006F0073, null, 0) WHERE diagram_id = @id -- index:22017
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00660074002E0056006300350035003000390065003600310023005C0036, null, 0) WHERE diagram_id = @id -- index:22049
    UPDATE sysdiagrams SET [definition] .Write ( 0x0035003900380032003300360036006100610038003600640035003600620037, null, 0) WHERE diagram_id = @id -- index:22081
    UPDATE sysdiagrams SET [definition] .Write ( 0x006200390031006200350061003600350062006100380037003000340038005C, null, 0) WHERE diagram_id = @id -- index:22113
    UPDATE sysdiagrams SET [definition] .Write ( 0x004D006900630072006F0073006F00660074002E00560069007300750061006C, null, 0) WHERE diagram_id = @id -- index:22145
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000100000005000000540000002C0000002C0000002C, null, 0) WHERE diagram_id = @id -- index:22177
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000003400000000000000000000002229000065150000000000002D01000007, null, 0) WHERE diagram_id = @id -- index:22209
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000C000000070000001C0100000609000062070000480300001A040000DF, null, 0) WHERE diagram_id = @id -- index:22241
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000EC04000027060000B103000027060000CB070000550500000000000001, null, 0) WHERE diagram_id = @id -- index:22273
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000F7290000180C000000000000030000000300000002000000020000001C, null, 0) WHERE diagram_id = @id -- index:22305
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000008160000000000000100000039130000060A0000000000000300000003, null, 0) WHERE diagram_id = @id -- index:22337
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000002000000020000001C0100000609000001000000000000003913000034, null, 0) WHERE diagram_id = @id -- index:22369
    UPDATE sysdiagrams SET [definition] .Write ( 0x03000000000000000000000000000002000000020000001C0100000609000000, null, 0) WHERE diagram_id = @id -- index:22401
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000D13100000923000000000000000000000D0000000400000004, null, 0) WHERE diagram_id = @id -- index:22433
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000001C01000006090000AA0A00009006000078563412040000009800000001, null, 0) WHERE diagram_id = @id -- index:22465
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000010000000B000000000000000100000002000000030000000400000005, null, 0) WHERE diagram_id = @id -- index:22497
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000060000000700000008000000090000000A0000000900000073006E0061, null, 0) WHERE diagram_id = @id -- index:22529
    UPDATE sysdiagrams SET [definition] .Write ( 0x007000730068006F007400000023000000470072006F007500700049006E0073, null, 0) WHERE diagram_id = @id -- index:22561
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740061006E006300650045006C0065006D0065006E00740049006E00730074, null, 0) WHERE diagram_id = @id -- index:22593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061006E00630065004C006F006F006B0075007000000004000B008C550000BE, null, 0) WHERE diagram_id = @id -- index:22625
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0000704E0000BE6E0000704E000078690000894C0000786900000000000002, null, 0) WHERE diagram_id = @id -- index:22657
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000F0F0F00001000000000000000000000000000000010000002100000000, null, 0) WHERE diagram_id = @id -- index:22689
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000332D0000656F00008E20000058010000320000000100000200008E2000, null, 0) WHERE diagram_id = @id -- index:22721
    UPDATE sysdiagrams SET [definition] .Write ( 0x0058010000020000000000050000800800008001000000150001000000900144, null, 0) WHERE diagram_id = @id -- index:22753
    UPDATE sysdiagrams SET [definition] .Write ( 0x420100065461686F6D61350046004B005F00470072006F007500700049006E00, null, 0) WHERE diagram_id = @id -- index:22785
    UPDATE sysdiagrams SET [definition] .Write ( 0x7300740061006E006300650045006C0065006D0065006E00740049006E007300, null, 0) WHERE diagram_id = @id -- index:22817
    UPDATE sysdiagrams SET [definition] .Write ( 0x740061006E00630065004C006F006F006B00750070005F0045006C0065006D00, null, 0) WHERE diagram_id = @id -- index:22849
    UPDATE sysdiagrams SET [definition] .Write ( 0x65006E00740049006E007300740061006E006300650004000B00422700004A79, null, 0) WHERE diagram_id = @id -- index:22881
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000422700002F720000AA3700002F720000AA370000B46F0000000000000200, null, 0) WHERE diagram_id = @id -- index:22913
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000F0F0F0000000000000000000000000000000000001000000230000000000, null, 0) WHERE diagram_id = @id -- index:22945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000D52D0000DE7200008A1F000058010000320000000100000200008A1F0000, null, 0) WHERE diagram_id = @id -- index:22977
    UPDATE sysdiagrams SET [definition] .Write ( 0x5801000002000000000005000080080000800100000015000100000090014442, null, 0) WHERE diagram_id = @id -- index:23009
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100065461686F6D61330046004B005F00470072006F007500700049006E0073, null, 0) WHERE diagram_id = @id -- index:23041
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740061006E006300650045006C0065006D0065006E00740049006E00730074, null, 0) WHERE diagram_id = @id -- index:23073
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061006E00630065004C006F006F006B00750070005F00470072006F00750070, null, 0) WHERE diagram_id = @id -- index:23105
    UPDATE sysdiagrams SET [definition] .Write ( 0x0049006E007300740061006E006300650021433412080000001E190000C83300, null, 0) WHERE diagram_id = @id -- index:23137
    UPDATE sysdiagrams SET [definition] .Write ( 0x00785634120700000014010000470072006F007500700049006E007300740061, null, 0) WHERE diagram_id = @id -- index:23169
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E006300650050006100720061006D006500740065007200560061006C0075, null, 0) WHERE diagram_id = @id -- index:23201
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065002000280073006E0061007000730068006F007400290000008D0ACF778D, null, 0) WHERE diagram_id = @id -- index:23233
    UPDATE sysdiagrams SET [definition] .Write ( 0x0AF3778D0A17788D0A3B788D0A5F788D0A83788D0AA7788D0ACB788D0AEF788D, null, 0) WHERE diagram_id = @id -- index:23265
    UPDATE sysdiagrams SET [definition] .Write ( 0x0A13798D0A37798D0A5B798D0A7F798D0AA3798D0AC7798D0AEB798D0A0F7A8D, null, 0) WHERE diagram_id = @id -- index:23297
    UPDATE sysdiagrams SET [definition] .Write ( 0x0A337A8D0A577A8D0A7B7A8D0A9F7A8D0AC37A8D0AE77A8D0A0B7B8D0A2F7B8D, null, 0) WHERE diagram_id = @id -- index:23329
    UPDATE sysdiagrams SET [definition] .Write ( 0x0A537B8D0A777B8D0A9B7B8D0ABF7B8D0AE37B8D0A077C8D0A2B7C8D0A4F7C8D, null, 0) WHERE diagram_id = @id -- index:23361
    UPDATE sysdiagrams SET [definition] .Write ( 0x0A737C8D0AA77C8D0ACB7C8D0AEF7C8D0A137D8D0A377D8D0A5B7D0000000000, null, 0) WHERE diagram_id = @id -- index:23393
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000100000005000000540000002C0000002C0000002C000000340000, null, 0) WHERE diagram_id = @id -- index:23425
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000002229000009230000000000002D0100000D0000000C0000, null, 0) WHERE diagram_id = @id -- index:23457
    UPDATE sysdiagrams SET [definition] .Write ( 0x00070000001C0100000609000062070000480300001A040000DF020000EC0400, null, 0) WHERE diagram_id = @id -- index:23489
    UPDATE sysdiagrams SET [definition] .Write ( 0x0027060000B103000027060000CB0700005505000000000000010000001E1900, null, 0) WHERE diagram_id = @id -- index:23521
    UPDATE sysdiagrams SET [definition] .Write ( 0x00C833000000000000130000000C00000002000000020000001C0100006C0C00, null, 0) WHERE diagram_id = @id -- index:23553
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000100000039130000C0070000000000000200000002000000020000, null, 0) WHERE diagram_id = @id -- index:23585
    UPDATE sysdiagrams SET [definition] .Write ( 0x00020000001C0100000609000001000000000000003913000034030000000000, null, 0) WHERE diagram_id = @id -- index:23617
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000002000000020000001C0100000609000000000000000000, null, 0) WHERE diagram_id = @id -- index:23649
    UPDATE sysdiagrams SET [definition] .Write ( 0x00D13100000923000000000000000000000D00000004000000040000001C0100, null, 0) WHERE diagram_id = @id -- index:23681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0006090000AA0A00009006000078563412040000008A00000001000000010000, null, 0) WHERE diagram_id = @id -- index:23713
    UPDATE sysdiagrams SET [definition] .Write ( 0x000B000000000000000100000002000000030000000400000005000000060000, null, 0) WHERE diagram_id = @id -- index:23745
    UPDATE sysdiagrams SET [definition] .Write ( 0x000700000008000000090000000A0000000900000073006E0061007000730068, null, 0) WHERE diagram_id = @id -- index:23777
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00740000001C000000470072006F007500700049006E007300740061006E, null, 0) WHERE diagram_id = @id -- index:23809
    UPDATE sysdiagrams SET [definition] .Write ( 0x006300650050006100720061006D006500740065007200560061006C00750065, null, 0) WHERE diagram_id = @id -- index:23841
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000004000B00802500004A790000802500002F7200004E0C00002F7200004E, null, 0) WHERE diagram_id = @id -- index:23873
    UPDATE sysdiagrams SET [definition] .Write ( 0x0C00008C6F00000000000002000000F0F0F00000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:23905
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000010000002600000000000000D21B000028700000F01B00005801000032, null, 0) WHERE diagram_id = @id -- index:23937
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000010000020000F01B000058010000020000000000050000800800008001, null, 0) WHERE diagram_id = @id -- index:23969
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000150001000000900144420100065461686F6D612D0046004B005F004700, null, 0) WHERE diagram_id = @id -- index:24001
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006F007500700049006E007300740061006E00630065005000610072006100, null, 0) WHERE diagram_id = @id -- index:24033
    UPDATE sysdiagrams SET [definition] .Write ( 0x6D006500740065007200560061006C00750065005F00470072006F0075007000, null, 0) WHERE diagram_id = @id -- index:24065
    UPDATE sysdiagrams SET [definition] .Write ( 0x49006E007300740061006E00630065003100214334120800000088160000930E, null, 0) WHERE diagram_id = @id -- index:24097
    UPDATE sysdiagrams SET [definition] .Write ( 0x00007856341207000000140100004C0069006E00650050006100740074006500, null, 0) WHERE diagram_id = @id -- index:24129
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006E002000280073006E0061007000730068006F00740029000000FFFF0000, null, 0) WHERE diagram_id = @id -- index:24161
    UPDATE sysdiagrams SET [definition] .Write ( 0x000010010000A5010000040000000000000007000000F0FFFFFF00000000A901, null, 0) WHERE diagram_id = @id -- index:24193
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000A6020000030000000300000005000000F0FFFFFF0000000022020000B802, null, 0) WHERE diagram_id = @id -- index:24225
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000050000000000000007000000F0FFFFFF0000000016000000C70200000000, null, 0) WHERE diagram_id = @id -- index:24257
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000006000000F0FFFFFF00000000BB020000C7020000030000000300, null, 0) WHERE diagram_id = @id -- index:24289
    UPDATE sysdiagrams SET [definition] .Write ( 0x000005000000F0FFFFFF00000000E0020000ED02000001000000000000000600, null, 0) WHERE diagram_id = @id -- index:24321
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000F0FFFFFF00000000F0000000EF0200000600000003000000050000000000, null, 0) WHERE diagram_id = @id -- index:24353
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000100000005000000540000002C0000002C0000002C0000003400, null, 0) WHERE diagram_id = @id -- index:24385
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000002229000065150000000000002D010000070000000C00, null, 0) WHERE diagram_id = @id -- index:24417
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000070000001C0100000609000062070000480300001A040000DF020000EC04, null, 0) WHERE diagram_id = @id -- index:24449
    UPDATE sysdiagrams SET [definition] .Write ( 0x000027060000B103000027060000CB0700005505000000000000010000008816, null, 0) WHERE diagram_id = @id -- index:24481
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000930E000000000000040000000400000002000000020000001C010000F50A, null, 0) WHERE diagram_id = @id -- index:24513
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000100000039130000C00700000000000002000000020000000200, null, 0) WHERE diagram_id = @id -- index:24545
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000001C01000006090000010000000000000039130000340300000000, null, 0) WHERE diagram_id = @id -- index:24577
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000002000000020000001C01000006090000000000000000, null, 0) WHERE diagram_id = @id -- index:24609
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000D13100000923000000000000000000000D00000004000000040000001C01, null, 0) WHERE diagram_id = @id -- index:24641
    UPDATE sysdiagrams SET [definition] .Write ( 0x000006090000AA0A00009006000078563412040000006A000000010000000100, null, 0) WHERE diagram_id = @id -- index:24673
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000B0000000000000001000000020000000300000004000000050000000600, null, 0) WHERE diagram_id = @id -- index:24705
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000700000008000000090000000A0000000900000073006E00610070007300, null, 0) WHERE diagram_id = @id -- index:24737
    UPDATE sysdiagrams SET [definition] .Write ( 0x68006F00740000000C0000004C0069006E006500500061007400740065007200, null, 0) WHERE diagram_id = @id -- index:24769
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E000000214334120800000088160000930E0000785634120700000014010000, null, 0) WHERE diagram_id = @id -- index:24801
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C006F00670041006400640049006E0020002800700061006C00290000006D00, null, 0) WHERE diagram_id = @id -- index:24833
    UPDATE sysdiagrams SET [definition] .Write ( 0x2000460069006C00650073002000280078003800360029002F004D0069006300, null, 0) WHERE diagram_id = @id -- index:24865
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006F0073006F00660074002000530051004C00200053006500720076006500, null, 0) WHERE diagram_id = @id -- index:24897
    UPDATE sysdiagrams SET [definition] .Write ( 0x72002F003100340030002F0054006F006F006C0073002F00420069006E006E00, null, 0) WHERE diagram_id = @id -- index:24929
    UPDATE sysdiagrams SET [definition] .Write ( 0x2F004D0061006E006100670065006D0065006E00740053007400750064006900, null, 0) WHERE diagram_id = @id -- index:24961
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F002F004900440045002F005300740061007200740050006100670065004100, null, 0) WHERE diagram_id = @id -- index:24993
    UPDATE sysdiagrams SET [definition] .Write ( 0x7300730065006D0062006C006900650073002F004D006900630072006F007300, null, 0) WHERE diagram_id = @id -- index:25025
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00660074002E00530071006C00000000000000000000000100000005000000, null, 0) WHERE diagram_id = @id -- index:25057
    UPDATE sysdiagrams SET [definition] .Write ( 0x540000002C0000002C0000002C00000034000000000000000000000022290000, null, 0) WHERE diagram_id = @id -- index:25089
    UPDATE sysdiagrams SET [definition] .Write ( 0x65150000000000002D010000070000000C000000070000001C01000006090000, null, 0) WHERE diagram_id = @id -- index:25121
    UPDATE sysdiagrams SET [definition] .Write ( 0x62070000480300001A040000DF020000EC04000027060000B103000027060000, null, 0) WHERE diagram_id = @id -- index:25153
    UPDATE sysdiagrams SET [definition] .Write ( 0xCB07000055050000000000000100000088160000930E00000000000004000000, null, 0) WHERE diagram_id = @id -- index:25185
    UPDATE sysdiagrams SET [definition] .Write ( 0x0400000002000000020000001C010000F50A0000000000000100000039130000, null, 0) WHERE diagram_id = @id -- index:25217
    UPDATE sysdiagrams SET [definition] .Write ( 0xC007000000000000020000000200000002000000020000001C01000006090000, null, 0) WHERE diagram_id = @id -- index:25249
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000000000000391300003403000000000000000000000000000002000000, null, 0) WHERE diagram_id = @id -- index:25281
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000001C010000060900000000000000000000D13100000923000000000000, null, 0) WHERE diagram_id = @id -- index:25313
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000D00000004000000040000001C01000006090000AA0A000090060000, null, 0) WHERE diagram_id = @id -- index:25345
    UPDATE sysdiagrams SET [definition] .Write ( 0x78563412040000005A00000001000000010000000B0000000000000001000000, null, 0) WHERE diagram_id = @id -- index:25377
    UPDATE sysdiagrams SET [definition] .Write ( 0x0200000003000000040000000500000006000000070000000800000009000000, null, 0) WHERE diagram_id = @id -- index:25409
    UPDATE sysdiagrams SET [definition] .Write ( 0x0A00000004000000700061006C000000090000004C006F006700410064006400, null, 0) WHERE diagram_id = @id -- index:25441
    UPDATE sysdiagrams SET [definition] .Write ( 0x49006E000000214334120800000088160000751D000078563412070000001401, null, 0) WHERE diagram_id = @id -- index:25473
    UPDATE sysdiagrams SET [definition] .Write ( 0x00004C006F0067004300720061007300680020002800700061006C0029000000, null, 0) WHERE diagram_id = @id -- index:25505
    UPDATE sysdiagrams SET [definition] .Write ( 0x441B08CC441B602B4F1BFC2A4F1B44F77B0204F77B02389B7B02F49A7B027CC9, null, 0) WHERE diagram_id = @id -- index:25537
    UPDATE sysdiagrams SET [definition] .Write ( 0x441BDCC8441B0CCB441B9CCA441B00000000D81BDB2700000000EC1BDB2798C8, null, 0) WHERE diagram_id = @id -- index:25569
    UPDATE sysdiagrams SET [definition] .Write ( 0x441B5CC8441B00000000FC1BDB2700000000041CDB27AC874C2538874C25101F, null, 0) WHERE diagram_id = @id -- index:25601
    UPDATE sysdiagrams SET [definition] .Write ( 0x4F1BD01E4F1B14CC5428D8CB542800000000541CDB27000000005C1CDB2790B3, null, 0) WHERE diagram_id = @id -- index:25633
    UPDATE sysdiagrams SET [definition] .Write ( 0x3F1B50B33F1BE47586008C758600A8D9321B64D9321BC0544F1B8C544F1B64DA, null, 0) WHERE diagram_id = @id -- index:25665
    UPDATE sysdiagrams SET [definition] .Write ( 0x321B18DA321BB0553D2854553D2828BD3D28D0BC3D28E0C23D2898C23D285C9C, null, 0) WHERE diagram_id = @id -- index:25697
    UPDATE sysdiagrams SET [definition] .Write ( 0x7B02BC9B7B02AC0145256401452504C300000000000000000000010000000500, null, 0) WHERE diagram_id = @id -- index:25729
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000540000002C0000002C0000002C0000003400000000000000000000002229, null, 0) WHERE diagram_id = @id -- index:25761
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000C3200000000000002D0100000C0000000C000000070000001C0100000609, null, 0) WHERE diagram_id = @id -- index:25793
    UPDATE sysdiagrams SET [definition] .Write ( 0x000062070000480300001A040000DF020000EC04000027060000B10300002706, null, 0) WHERE diagram_id = @id -- index:25825
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000CB07000055050000000000000100000088160000751D0000000000000A00, null, 0) WHERE diagram_id = @id -- index:25857
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000A00000002000000020000001C010000F50A000000000000010000003913, null, 0) WHERE diagram_id = @id -- index:25889
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000C007000000000000020000000200000002000000020000001C0100000609, null, 0) WHERE diagram_id = @id -- index:25921
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000010000000000000039130000340300000000000000000000000000000200, null, 0) WHERE diagram_id = @id -- index:25953
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000001C010000060900000000000000000000D1310000092300000000, null, 0) WHERE diagram_id = @id -- index:25985
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000D00000004000000040000001C01000006090000AA0A00009006, null, 0) WHERE diagram_id = @id -- index:26017
    UPDATE sysdiagrams SET [definition] .Write ( 0x000078563412040000005A00000001000000010000000B000000000000000100, null, 0) WHERE diagram_id = @id -- index:26049
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000000300000004000000050000000600000007000000080000000900, null, 0) WHERE diagram_id = @id -- index:26081
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000A00000004000000700061006C000000090000004C006F00670043007200, null, 0) WHERE diagram_id = @id -- index:26113
    UPDATE sysdiagrams SET [definition] .Write ( 0x6100730068000000214334120800000088160000327E00007856341207000000, null, 0) WHERE diagram_id = @id -- index:26145
    UPDATE sysdiagrams SET [definition] .Write ( 0x140100004C006F00670044006F006300530065007300730069006F006E002000, null, 0) WHERE diagram_id = @id -- index:26177
    UPDATE sysdiagrams SET [definition] .Write ( 0x2800700061006C0029000000650073002000280078003800360029002F004D00, null, 0) WHERE diagram_id = @id -- index:26209
    UPDATE sysdiagrams SET [definition] .Write ( 0x6900630072006F0073006F00660074002000530051004C002000530065007200, null, 0) WHERE diagram_id = @id -- index:26241
    UPDATE sysdiagrams SET [definition] .Write ( 0x7600650072002F003100340030002F0054006F006F006C0073002F0042006900, null, 0) WHERE diagram_id = @id -- index:26273
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E006E002F004D0061006E006100670065006D0065006E007400530074007500, null, 0) WHERE diagram_id = @id -- index:26305
    UPDATE sysdiagrams SET [definition] .Write ( 0x640069006F002F004900440045002F0043006F006D0070006F006E0065006E00, null, 0) WHERE diagram_id = @id -- index:26337
    UPDATE sysdiagrams SET [definition] .Write ( 0x740073002F004D006900630072006F0073006F00660074002E00530071006C00, null, 0) WHERE diagram_id = @id -- index:26369
    UPDATE sysdiagrams SET [definition] .Write ( 0x5300650072007600650072002E004D0061000000000000000000000001000000, null, 0) WHERE diagram_id = @id -- index:26401
    UPDATE sysdiagrams SET [definition] .Write ( 0x05000000540000002C0000002C0000002C000000340000000000000000000000, null, 0) WHERE diagram_id = @id -- index:26433
    UPDATE sysdiagrams SET [definition] .Write ( 0x2229000009230000000000002D0100000D0000000C000000070000001C010000, null, 0) WHERE diagram_id = @id -- index:26465
    UPDATE sysdiagrams SET [definition] .Write ( 0x0609000062070000480300001A040000DF020000EC04000027060000B1030000, null, 0) WHERE diagram_id = @id -- index:26497
    UPDATE sysdiagrams SET [definition] .Write ( 0x27060000CB07000055050000000000000100000088160000327E000000000000, null, 0) WHERE diagram_id = @id -- index:26529
    UPDATE sysdiagrams SET [definition] .Write ( 0x310000000C00000002000000020000001C010000F50A00000000000001000000, null, 0) WHERE diagram_id = @id -- index:26561
    UPDATE sysdiagrams SET [definition] .Write ( 0x391300004D0C000000000000040000000400000002000000020000001C010000, null, 0) WHERE diagram_id = @id -- index:26593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0609000001000000000000003913000034030000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:26625
    UPDATE sysdiagrams SET [definition] .Write ( 0x02000000020000001C010000060900000000000000000000D131000009230000, null, 0) WHERE diagram_id = @id -- index:26657
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000D00000004000000040000001C01000006090000AA0A0000, null, 0) WHERE diagram_id = @id -- index:26689
    UPDATE sysdiagrams SET [definition] .Write ( 0x9006000078563412040000006400000001000000010000000B00000000000000, null, 0) WHERE diagram_id = @id -- index:26721
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000002000000030000000400000005000000060000000700000008000000, null, 0) WHERE diagram_id = @id -- index:26753
    UPDATE sysdiagrams SET [definition] .Write ( 0x090000000A00000004000000700061006C0000000E0000004C006F0067004400, null, 0) WHERE diagram_id = @id -- index:26785
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F006300530065007300730069006F006E00000004000B0066B7000016710000, null, 0) WHERE diagram_id = @id -- index:26817
    UPDATE sysdiagrams SET [definition] .Write ( 0x66B700005B680000EE9800005B680000EE980000E16500000000000002000000, null, 0) WHERE diagram_id = @id -- index:26849
    UPDATE sysdiagrams SET [definition] .Write ( 0xF0F0F00000000000000000000000000000000000010000002C00000000000000, null, 0) WHERE diagram_id = @id -- index:26881
    UPDATE sysdiagrams SET [definition] .Write ( 0x199B00000A690000E20F00005801000031000000010000020000E20F00005801, null, 0) WHERE diagram_id = @id -- index:26913
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000000000050000800800008001000000150001000000900144420100, null, 0) WHERE diagram_id = @id -- index:26945
    UPDATE sysdiagrams SET [definition] .Write ( 0x065461686F6D61190046004B005F004C006F00670041006400640049006E005F, null, 0) WHERE diagram_id = @id -- index:26977
    UPDATE sysdiagrams SET [definition] .Write ( 0x004C006F00670044006F006300530065007300730069006F006E0004000B0006, null, 0) WHERE diagram_id = @id -- index:27009
    UPDATE sysdiagrams SET [definition] .Write ( 0xAE000006AE00009EA7000006AE00009EA70000FA7D000054A40000FA7D000000, null, 0) WHERE diagram_id = @id -- index:27041
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000002000000F0F0F00000000000000000000000000000000000010000002E, null, 0) WHERE diagram_id = @id -- index:27073
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000002A97000001990000C50F000058010000310000000100000200, null, 0) WHERE diagram_id = @id -- index:27105
    UPDATE sysdiagrams SET [definition] .Write ( 0x00C50F0000580100000200000000000500008008000080010000001500010000, null, 0) WHERE diagram_id = @id -- index:27137
    UPDATE sysdiagrams SET [definition] .Write ( 0x00900144420100065461686F6D61190046004B005F004C006F00670043007200, null, 0) WHERE diagram_id = @id -- index:27169
    UPDATE sysdiagrams SET [definition] .Write ( 0x6100730068005F004C006F00670044006F006300530065007300730069006F00, null, 0) WHERE diagram_id = @id -- index:27201
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0021433412080000002F1B0000041600007856341207000000140100004C00, null, 0) WHERE diagram_id = @id -- index:27233
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00670044006F00630075006D0065006E007400500072006F006A0043006800, null, 0) WHERE diagram_id = @id -- index:27265
    UPDATE sysdiagrams SET [definition] .Write ( 0x61006E006700650020002800700061006C00290000002F004D00690063007200, null, 0) WHERE diagram_id = @id -- index:27297
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F0073006F00660074002000530051004C002000530065007200760065007200, null, 0) WHERE diagram_id = @id -- index:27329
    UPDATE sysdiagrams SET [definition] .Write ( 0x2F003100340030002F0054006F006F006C0073002F00420069006E006E002F00, null, 0) WHERE diagram_id = @id -- index:27361
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D0061006E006100670065006D0065006E007400530074007500640069006F00, null, 0) WHERE diagram_id = @id -- index:27393
    UPDATE sysdiagrams SET [definition] .Write ( 0x2F004900440045002F0043006F006D006D006F006E0045007800740065006E00, null, 0) WHERE diagram_id = @id -- index:27425
    UPDATE sysdiagrams SET [definition] .Write ( 0x730069006F006E0073002F0050006C006100740066006F0072006D002F004D00, null, 0) WHERE diagram_id = @id -- index:27457
    UPDATE sysdiagrams SET [definition] .Write ( 0x6900630072006F0073006F000000000000000000000001000000050000005400, null, 0) WHERE diagram_id = @id -- index:27489
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002C0000002C0000002C00000034000000000000000000000022290000F119, null, 0) WHERE diagram_id = @id -- index:27521
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000002D010000090000000C000000070000001C010000060900006207, null, 0) WHERE diagram_id = @id -- index:27553
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000480300001A040000DF020000EC04000027060000B103000027060000CB07, null, 0) WHERE diagram_id = @id -- index:27585
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005505000000000000010000002F1B00000416000000000000070000000700, null, 0) WHERE diagram_id = @id -- index:27617
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002000000020000001C010000980D0000000000000100000039130000C007, null, 0) WHERE diagram_id = @id -- index:27649
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000020000000200000002000000020000001C010000060900000100, null, 0) WHERE diagram_id = @id -- index:27681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000003913000034030000000000000000000000000000020000000200, null, 0) WHERE diagram_id = @id -- index:27713
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001C010000060900000000000000000000D131000009230000000000000000, null, 0) WHERE diagram_id = @id -- index:27745
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000D00000004000000040000001C01000006090000AA0A0000900600007856, null, 0) WHERE diagram_id = @id -- index:27777
    UPDATE sysdiagrams SET [definition] .Write ( 0x3412040000007400000001000000010000000B00000000000000010000000200, null, 0) WHERE diagram_id = @id -- index:27809
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000030000000400000005000000060000000700000008000000090000000A00, null, 0) WHERE diagram_id = @id -- index:27841
    UPDATE sysdiagrams SET [definition] .Write ( 0x000004000000700061006C000000160000004C006F00670044006F0063007500, null, 0) WHERE diagram_id = @id -- index:27873
    UPDATE sysdiagrams SET [definition] .Write ( 0x6D0065006E007400500072006F006A004300680061006E006700650000000400, null, 0) WHERE diagram_id = @id -- index:27905
    UPDATE sysdiagrams SET [definition] .Write ( 0x0B008EC4000006AE0000F6CA000006AE0000F6CA0000748B0000AACD0000748B, null, 0) WHERE diagram_id = @id -- index:27937
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000002000000F0F0F000000000000000000000000000000000000100, null, 0) WHERE diagram_id = @id -- index:27969
    UPDATE sysdiagrams SET [definition] .Write ( 0x00003100000000000000A5CB0000469F00005518000058010000320000000100, null, 0) WHERE diagram_id = @id -- index:28001
    UPDATE sysdiagrams SET [definition] .Write ( 0x0002000055180000580100000200000000000500008008000080010000001500, null, 0) WHERE diagram_id = @id -- index:28033
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000000900144420100065461686F6D61260046004B005F004C006F00670044, null, 0) WHERE diagram_id = @id -- index:28065
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00630075006D0065006E007400500072006F006A004300680061006E0067, null, 0) WHERE diagram_id = @id -- index:28097
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065005F004C006F00670044006F006300530065007300730069006F006E0021, null, 0) WHERE diagram_id = @id -- index:28129
    UPDATE sysdiagrams SET [definition] .Write ( 0x43341208000000881600000E1100007856341207000000140100004C006F0067, null, 0) WHERE diagram_id = @id -- index:28161
    UPDATE sysdiagrams SET [definition] .Write ( 0x0045006C0065006D0065006E00740020002800700061006C0029000000000000, null, 0) WHERE diagram_id = @id -- index:28193
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000D09D400000000000308C40000000000000F03F00, null, 0) WHERE diagram_id = @id -- index:28225
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000010000000100000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:28257
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:28289
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000F03F0000000000000000C4AB8A680000000000000000846C8B681C, null, 0) WHERE diagram_id = @id -- index:28321
    UPDATE sysdiagrams SET [definition] .Write ( 0x588B6800000000E8047E21020000000300000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:28353
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000200000000000000000000000000000000806144008061C40000000000, null, 0) WHERE diagram_id = @id -- index:28385
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000000000000000100000005000000540000002C, null, 0) WHERE diagram_id = @id -- index:28417
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000002C0000002C000000340000000000000000000000222900006515000000, null, 0) WHERE diagram_id = @id -- index:28449
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000002D010000070000000C000000070000001C010000060900006207000048, null, 0) WHERE diagram_id = @id -- index:28481
    UPDATE sysdiagrams SET [definition] .Write ( 0x0300001A040000DF020000EC04000027060000B103000027060000CB07000055, null, 0) WHERE diagram_id = @id -- index:28513
    UPDATE sysdiagrams SET [definition] .Write ( 0x0500000000000001000000881600000E11000000000000050000000500000002, null, 0) WHERE diagram_id = @id -- index:28545
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000020000001C010000F50A0000000000000100000039130000C007000000, null, 0) WHERE diagram_id = @id -- index:28577
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000020000000200000002000000020000001C010000060900000100000000, null, 0) WHERE diagram_id = @id -- index:28609
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000391300003403000000000000000000000000000002000000020000001C, null, 0) WHERE diagram_id = @id -- index:28641
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000060900000000000000000000D13100000923000000000000000000000D, null, 0) WHERE diagram_id = @id -- index:28673
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000004000000040000001C01000006090000AA0A0000900600007856341204, null, 0) WHERE diagram_id = @id -- index:28705
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000005E00000001000000010000000B00000000000000010000000200000003, null, 0) WHERE diagram_id = @id -- index:28737
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000400000005000000060000000700000008000000090000000A00000004, null, 0) WHERE diagram_id = @id -- index:28769
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000700061006C0000000B0000004C006F00670045006C0065006D0065006E, null, 0) WHERE diagram_id = @id -- index:28801
    UPDATE sysdiagrams SET [definition] .Write ( 0x007400000004000B0028B9000048EF000028B9000003F80000BEB9000003F800, null, 0) WHERE diagram_id = @id -- index:28833
    UPDATE sysdiagrams SET [definition] .Write ( 0x00BEB9000032FA00000000000002000000F0F0F0000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:28865
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000001000000340000000000000093A700007BF50000E6100000580100, null, 0) WHERE diagram_id = @id -- index:28897
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032000000010000020000E61000005801000002000000000005000080080000, null, 0) WHERE diagram_id = @id -- index:28929
    UPDATE sysdiagrams SET [definition] .Write ( 0x8001000000150001000000900144420100065461686F6D611B0046004B005F00, null, 0) WHERE diagram_id = @id -- index:28961
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C006F00670045006C0065006D0065006E0074005F004C006F00670044006F00, null, 0) WHERE diagram_id = @id -- index:28993
    UPDATE sysdiagrams SET [definition] .Write ( 0x6300530065007300730069006F006E00214334120800000088160000930E0000, null, 0) WHERE diagram_id = @id -- index:29025
    UPDATE sysdiagrams SET [definition] .Write ( 0x7856341207000000140100004C006F00670045004E0055004D00200028007000, null, 0) WHERE diagram_id = @id -- index:29057
    UPDATE sysdiagrams SET [definition] .Write ( 0x61006C0029000000000000000000000000000000000000000000000000009E40, null, 0) WHERE diagram_id = @id -- index:29089
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000004A40000000000000F03F00000000000000000000000001000000, null, 0) WHERE diagram_id = @id -- index:29121
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:29153
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000000000000000000000000F03F0000000000000000, null, 0) WHERE diagram_id = @id -- index:29185
    UPDATE sysdiagrams SET [definition] .Write ( 0xC4AB8A680000000000000000846C8B681C588B6800000000080A7E2102000000, null, 0) WHERE diagram_id = @id -- index:29217
    UPDATE sysdiagrams SET [definition] .Write ( 0x0300000000000000000000000000000000000000020000000000000000000000, null, 0) WHERE diagram_id = @id -- index:29249
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000005042000050C20000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:29281
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000100000005000000540000002C0000002C0000002C00000034000000, null, 0) WHERE diagram_id = @id -- index:29313
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000002229000065150000000000002D010000070000000C000000, null, 0) WHERE diagram_id = @id -- index:29345
    UPDATE sysdiagrams SET [definition] .Write ( 0x070000001C0100000609000062070000480300001A040000DF020000EC040000, null, 0) WHERE diagram_id = @id -- index:29377
    UPDATE sysdiagrams SET [definition] .Write ( 0x27060000B103000027060000CB07000055050000000000000100000088160000, null, 0) WHERE diagram_id = @id -- index:29409
    UPDATE sysdiagrams SET [definition] .Write ( 0x930E000000000000040000000400000002000000020000001C010000F50A0000, null, 0) WHERE diagram_id = @id -- index:29441
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000001000000391300007A05000000000000010000000100000002000000, null, 0) WHERE diagram_id = @id -- index:29473
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000001C010000060900000100000000000000391300003403000000000000, null, 0) WHERE diagram_id = @id -- index:29505
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000002000000020000001C010000060900000000000000000000, null, 0) WHERE diagram_id = @id -- index:29537
    UPDATE sysdiagrams SET [definition] .Write ( 0xD13100000923000000000000000000000D00000004000000040000001C010000, null, 0) WHERE diagram_id = @id -- index:29569
    UPDATE sysdiagrams SET [definition] .Write ( 0x06090000AA0A0000900600007856341204000000580000000100000001000000, null, 0) WHERE diagram_id = @id -- index:29601
    UPDATE sysdiagrams SET [definition] .Write ( 0x0B00000000000000010000000200000003000000040000000500000006000000, null, 0) WHERE diagram_id = @id -- index:29633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0700000008000000090000000A00000004000000700061006C00000008000000, null, 0) WHERE diagram_id = @id -- index:29665
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C006F00670045004E0055004D000000214334120800000088160000C8330000, null, 0) WHERE diagram_id = @id -- index:29697
    UPDATE sysdiagrams SET [definition] .Write ( 0x7856341207000000140100004C006F0067004500760065006E00740020002800, null, 0) WHERE diagram_id = @id -- index:29729
    UPDATE sysdiagrams SET [definition] .Write ( 0x700061006C002900000000000000000000000000000000400000000000807B40, null, 0) WHERE diagram_id = @id -- index:29761
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000003340000000000000F03F00000000000000000000000001000000, null, 0) WHERE diagram_id = @id -- index:29793
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:29825
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000000000000000000000000F03F0000000000000000, null, 0) WHERE diagram_id = @id -- index:29857
    UPDATE sysdiagrams SET [definition] .Write ( 0xC4AB8A680000000000000000846C8B681C588B680000000000137E2102000000, null, 0) WHERE diagram_id = @id -- index:29889
    UPDATE sysdiagrams SET [definition] .Write ( 0x0300000000000000000000000000000000000000020000000000000000000040, null, 0) WHERE diagram_id = @id -- index:29921
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000A841000098C10000004000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:29953
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000100000005000000540000002C0000002C0000002C00000034000000, null, 0) WHERE diagram_id = @id -- index:29985
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000002229000009230000000000002D0100000D0000000C000000, null, 0) WHERE diagram_id = @id -- index:30017
    UPDATE sysdiagrams SET [definition] .Write ( 0x070000001C0100000609000062070000480300001A040000DF020000EC040000, null, 0) WHERE diagram_id = @id -- index:30049
    UPDATE sysdiagrams SET [definition] .Write ( 0x27060000B103000027060000CB07000055050000000000000100000088160000, null, 0) WHERE diagram_id = @id -- index:30081
    UPDATE sysdiagrams SET [definition] .Write ( 0xC833000000000000130000000C00000002000000020000001C010000F50A0000, null, 0) WHERE diagram_id = @id -- index:30113
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000100000039130000C007000000000000020000000200000002000000, null, 0) WHERE diagram_id = @id -- index:30145
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000001C010000060900000100000000000000391300003403000000000000, null, 0) WHERE diagram_id = @id -- index:30177
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000002000000020000001C010000060900000000000000000000, null, 0) WHERE diagram_id = @id -- index:30209
    UPDATE sysdiagrams SET [definition] .Write ( 0xD13100000923000000000000000000000D00000004000000040000001C010000, null, 0) WHERE diagram_id = @id -- index:30241
    UPDATE sysdiagrams SET [definition] .Write ( 0x06090000AA0A00009006000078563412040000005A0000000100000001000000, null, 0) WHERE diagram_id = @id -- index:30273
    UPDATE sysdiagrams SET [definition] .Write ( 0x0B00000000000000010000000200000003000000040000000500000006000000, null, 0) WHERE diagram_id = @id -- index:30305
    UPDATE sysdiagrams SET [definition] .Write ( 0x0700000008000000090000000A00000004000000700061006C00000009000000, null, 0) WHERE diagram_id = @id -- index:30337
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C006F0067004500760065006E007400000004000B0006AE0000C8AF0000EAA6, null, 0) WHERE diagram_id = @id -- index:30369
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000C8AF0000EAA60000C8AF000054A40000C8AF00000000000002000000F0F0, null, 0) WHERE diagram_id = @id -- index:30401
    UPDATE sysdiagrams SET [definition] .Write ( 0xF00000000000000000000000000000000000010000003800000000000000F298, null, 0) WHERE diagram_id = @id -- index:30433
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000C1AD0000C50F00005801000032000000010000020000C50F000058010000, null, 0) WHERE diagram_id = @id -- index:30465
    UPDATE sysdiagrams SET [definition] .Write ( 0x0200000000000500008008000080010000001500010000009001444201000654, null, 0) WHERE diagram_id = @id -- index:30497
    UPDATE sysdiagrams SET [definition] .Write ( 0x61686F6D61190046004B005F004C006F0067004500760065006E0074005F004C, null, 0) WHERE diagram_id = @id -- index:30529
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00670044006F006300530065007300730069006F006E0021433412080000, null, 0) WHERE diagram_id = @id -- index:30561
    UPDATE sysdiagrams SET [definition] .Write ( 0x00881600007F1800007856341207000000140100004C006F0067004C0069006E, null, 0) WHERE diagram_id = @id -- index:30593
    UPDATE sysdiagrams SET [definition] .Write ( 0x006B0020002800700061006C0029000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:30625
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000400000000000308C40000000000000F03F00000000000000, null, 0) WHERE diagram_id = @id -- index:30657
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000010000000100000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:30689
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000000000000000000000000000000000000000000F0, null, 0) WHERE diagram_id = @id -- index:30721
    UPDATE sysdiagrams SET [definition] .Write ( 0x3F0000000000000000C4AB8A680000000000000000846C8B681C588B68000000, null, 0) WHERE diagram_id = @id -- index:30753
    UPDATE sysdiagrams SET [definition] .Write ( 0x00500B7E21020000000300000000000000000000000000000000000000020000, null, 0) WHERE diagram_id = @id -- index:30785
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000806144008061C40000000000000000000000, null, 0) WHERE diagram_id = @id -- index:30817
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000100000005000000540000002C0000002C0000, null, 0) WHERE diagram_id = @id -- index:30849
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C00000034000000000000000000000022290000371C0000000000002D0100, null, 0) WHERE diagram_id = @id -- index:30881
    UPDATE sysdiagrams SET [definition] .Write ( 0x000A0000000C000000070000001C0100000609000062070000480300001A0400, null, 0) WHERE diagram_id = @id -- index:30913
    UPDATE sysdiagrams SET [definition] .Write ( 0x00DF020000EC04000027060000B103000027060000CB07000055050000000000, null, 0) WHERE diagram_id = @id -- index:30945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0001000000881600007F18000000000000080000000800000002000000020000, null, 0) WHERE diagram_id = @id -- index:30977
    UPDATE sysdiagrams SET [definition] .Write ( 0x001C010000F50A0000000000000100000039130000C007000000000000020000, null, 0) WHERE diagram_id = @id -- index:31009
    UPDATE sysdiagrams SET [definition] .Write ( 0x000200000002000000020000001C010000060900000100000000000000391300, null, 0) WHERE diagram_id = @id -- index:31041
    UPDATE sysdiagrams SET [definition] .Write ( 0x003403000000000000000000000000000002000000020000001C010000060900, null, 0) WHERE diagram_id = @id -- index:31073
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000D13100000923000000000000000000000D000000040000, null, 0) WHERE diagram_id = @id -- index:31105
    UPDATE sysdiagrams SET [definition] .Write ( 0x00040000001C01000006090000AA0A0000900600007856341204000000580000, null, 0) WHERE diagram_id = @id -- index:31137
    UPDATE sysdiagrams SET [definition] .Write ( 0x0001000000010000000B00000000000000010000000200000003000000040000, null, 0) WHERE diagram_id = @id -- index:31169
    UPDATE sysdiagrams SET [definition] .Write ( 0x0005000000060000000700000008000000090000000A00000004000000700061, null, 0) WHERE diagram_id = @id -- index:31201
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C000000080000004C006F0067004C0069006E006B00000004000B008EC400, null, 0) WHERE diagram_id = @id -- index:31233
    UPDATE sysdiagrams SET [definition] .Write ( 0x008AB10000AACB00008AB10000AACB0000F0D20000AACD0000F0D20000000000, null, 0) WHERE diagram_id = @id -- index:31265
    UPDATE sysdiagrams SET [definition] .Write ( 0x0002000000F0F0F00000000000000000000000000000000000010000003B0000, null, 0) WHERE diagram_id = @id -- index:31297
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000056BC000068C00000A50E00005801000032000000010000020000A5, null, 0) WHERE diagram_id = @id -- index:31329
    UPDATE sysdiagrams SET [definition] .Write ( 0x0E00005801000002000000000005000080080000800100000015000100000090, null, 0) WHERE diagram_id = @id -- index:31361
    UPDATE sysdiagrams SET [definition] .Write ( 0x0144420100065461686F6D61180046004B005F004C006F0067004C0069006E00, null, 0) WHERE diagram_id = @id -- index:31393
    UPDATE sysdiagrams SET [definition] .Write ( 0x6B005F004C006F00670044006F006300530065007300730069006F006E002143, null, 0) WHERE diagram_id = @id -- index:31425
    UPDATE sysdiagrams SET [definition] .Write ( 0x34120800000088160000DC2900007856341207000000140100004C006F006700, null, 0) WHERE diagram_id = @id -- index:31457
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D0061006300680069006E00650020002800700061006C002900000000000B00, null, 0) WHERE diagram_id = @id -- index:31489
    UPDATE sysdiagrams SET [definition] .Write ( 0x000011000000170000001D000000250000002F0000003B000000470000005900, null, 0) WHERE diagram_id = @id -- index:31521
    UPDATE sysdiagrams SET [definition] .Write ( 0x00006B00000083000000A3000000C5000000EF0000002501000061010000AF01, null, 0) WHERE diagram_id = @id -- index:31553
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000902000077020000F9020000970300004F0400002F0500003D0600008B07, null, 0) WHERE diagram_id = @id -- index:31585
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001D090000F10A00002B0D0000D10F0000FD120000CF160000651B0000E320, null, 0) WHERE diagram_id = @id -- index:31617
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000772700006F2F0000FF3800006F4400001F5200008D62000055760000018E, null, 0) WHERE diagram_id = @id -- index:31649
    UPDATE sysdiagrams SET [definition] .Write ( 0x00006BAA000089CC000083F50000A72601009B61010057A801003BFD01001563, null, 0) WHERE diagram_id = @id -- index:31681
    UPDATE sysdiagrams SET [definition] .Write ( 0x020067DD02001B70000000000000000000000100000005000000540000002C00, null, 0) WHERE diagram_id = @id -- index:31713
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002C0000002C00000034000000000000000000000022290000092300000000, null, 0) WHERE diagram_id = @id -- index:31745
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002D0100000D0000000C000000070000001C01000006090000620700004803, null, 0) WHERE diagram_id = @id -- index:31777
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001A040000DF020000EC04000027060000B103000027060000CB0700005505, null, 0) WHERE diagram_id = @id -- index:31809
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000100000088160000DC290000000000000F0000000C0000000200, null, 0) WHERE diagram_id = @id -- index:31841
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000001C010000F50A0000000000000100000039130000C00700000000, null, 0) WHERE diagram_id = @id -- index:31873
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000000200000002000000020000001C01000006090000010000000000, null, 0) WHERE diagram_id = @id -- index:31905
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000391300003403000000000000000000000000000002000000020000001C01, null, 0) WHERE diagram_id = @id -- index:31937
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000060900000000000000000000D13100000923000000000000000000000D00, null, 0) WHERE diagram_id = @id -- index:31969
    UPDATE sysdiagrams SET [definition] .Write ( 0x000004000000040000001C01000006090000AA0A000090060000785634120400, null, 0) WHERE diagram_id = @id -- index:32001
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005E00000001000000010000000B0000000000000001000000020000000300, null, 0) WHERE diagram_id = @id -- index:32033
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000400000005000000060000000700000008000000090000000A0000000400, null, 0) WHERE diagram_id = @id -- index:32065
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000700061006C0000000B0000004C006F0067004D0061006300680069006E00, null, 0) WHERE diagram_id = @id -- index:32097
    UPDATE sysdiagrams SET [definition] .Write ( 0x6500000004000B00EABA000016710000EABA00000F690000CCD800000F690000, null, 0) WHERE diagram_id = @id -- index:32129
    UPDATE sysdiagrams SET [definition] .Write ( 0xCCD80000A06500000200000002000000F0F0F000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:32161
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000010000003E000000000000003EC80000BE6900000211000058010000, null, 0) WHERE diagram_id = @id -- index:32193
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200000001000002000002110000580100000200000000000500008008000080, null, 0) WHERE diagram_id = @id -- index:32225
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000000150001000000900144420100065461686F6D611B0046004B005F004C, null, 0) WHERE diagram_id = @id -- index:32257
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F0067004D0061006300680069006E0065005F004C006F00670044006F0063, null, 0) WHERE diagram_id = @id -- index:32289
    UPDATE sysdiagrams SET [definition] .Write ( 0x00530065007300730069006F006E00214334120800000088160000751D000078, null, 0) WHERE diagram_id = @id -- index:32321
    UPDATE sysdiagrams SET [definition] .Write ( 0x56341207000000140100004C006F0067005000720069006E0074002000280070, null, 0) WHERE diagram_id = @id -- index:32353
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061006C00290000006D002000460069006C0065007300200028007800380036, null, 0) WHERE diagram_id = @id -- index:32385
    UPDATE sysdiagrams SET [definition] .Write ( 0x0029002F004D006900630072006F0073006F00660074002000530051004C0020, null, 0) WHERE diagram_id = @id -- index:32417
    UPDATE sysdiagrams SET [definition] .Write ( 0x005300650072007600650072002F003100340030002F0054006F006F006C0073, null, 0) WHERE diagram_id = @id -- index:32449
    UPDATE sysdiagrams SET [definition] .Write ( 0x002F00420069006E006E002F004D0061006E006100670065006D0065006E0074, null, 0) WHERE diagram_id = @id -- index:32481
    UPDATE sysdiagrams SET [definition] .Write ( 0x00530074007500640069006F002F004900440045002F005000750062006C0069, null, 0) WHERE diagram_id = @id -- index:32513
    UPDATE sysdiagrams SET [definition] .Write ( 0x00630041007300730065006D0062006C006900650073002F004D006900630072, null, 0) WHERE diagram_id = @id -- index:32545
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F0073006F00660074002E00530071006C0053006500720000000000000000, null, 0) WHERE diagram_id = @id -- index:32577
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000005000000540000002C0000002C0000002C0000003400000000, null, 0) WHERE diagram_id = @id -- index:32609
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000022290000C3200000000000002D0100000C0000000C00000007, null, 0) WHERE diagram_id = @id -- index:32641
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000001C0100000609000062070000480300001A040000DF020000EC04000027, null, 0) WHERE diagram_id = @id -- index:32673
    UPDATE sysdiagrams SET [definition] .Write ( 0x060000B103000027060000CB0700005505000000000000010000008816000075, null, 0) WHERE diagram_id = @id -- index:32705
    UPDATE sysdiagrams SET [definition] .Write ( 0x1D0000000000000A0000000A00000002000000020000001C010000F50A000000, null, 0) WHERE diagram_id = @id -- index:32737
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000039130000C00700000000000002000000020000000200000002, null, 0) WHERE diagram_id = @id -- index:32769
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000001C01000006090000010000000000000039130000340300000000000000, null, 0) WHERE diagram_id = @id -- index:32801
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000002000000020000001C010000060900000000000000000000D1, null, 0) WHERE diagram_id = @id -- index:32833
    UPDATE sysdiagrams SET [definition] .Write ( 0x3100000923000000000000000000000D00000004000000040000001C01000006, null, 0) WHERE diagram_id = @id -- index:32865
    UPDATE sysdiagrams SET [definition] .Write ( 0x090000AA0A00009006000078563412040000005A00000001000000010000000B, null, 0) WHERE diagram_id = @id -- index:32897
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000001000000020000000300000004000000050000000600000007, null, 0) WHERE diagram_id = @id -- index:32929
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000008000000090000000A00000004000000700061006C000000090000004C, null, 0) WHERE diagram_id = @id -- index:32961
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F0067005000720069006E007400000004000B0006AE00008AB10000EAA600, null, 0) WHERE diagram_id = @id -- index:32993
    UPDATE sysdiagrams SET [definition] .Write ( 0x008AB10000EAA6000096E1000054A4000096E100000000000002000000F0F0F0, null, 0) WHERE diagram_id = @id -- index:33025
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000010000004100000000000000239700, null, 0) WHERE diagram_id = @id -- index:33057
    UPDATE sysdiagrams SET [definition] .Write ( 0x0046C50000180F00005801000032000000010000020000180F00005801000002, null, 0) WHERE diagram_id = @id -- index:33089
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000050000800800008001000000150001000000900144420100065461, null, 0) WHERE diagram_id = @id -- index:33121
    UPDATE sysdiagrams SET [definition] .Write ( 0x686F6D61190046004B005F004C006F0067005000720069006E0074005F004C00, null, 0) WHERE diagram_id = @id -- index:33153
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00670044006F006300530065007300730069006F006E002143341208000000, null, 0) WHERE diagram_id = @id -- index:33185
    UPDATE sysdiagrams SET [definition] .Write ( 0x88160000041600007856341207000000140100004C006F006700530065007300, null, 0) WHERE diagram_id = @id -- index:33217
    UPDATE sysdiagrams SET [definition] .Write ( 0x730069006F006E0020002800700061006C00290000005C004E00610074006900, null, 0) WHERE diagram_id = @id -- index:33249
    UPDATE sysdiagrams SET [definition] .Write ( 0x7600650049006D0061006700650073005F00760034002E0030002E0033003000, null, 0) WHERE diagram_id = @id -- index:33281
    UPDATE sysdiagrams SET [definition] .Write ( 0x3300310039005F00330032005C004D006900630072006F0073006F0066007400, null, 0) WHERE diagram_id = @id -- index:33313
    UPDATE sysdiagrams SET [definition] .Write ( 0x2E0053003100390036006100380065003300630023005C003300630063006500, null, 0) WHERE diagram_id = @id -- index:33345
    UPDATE sysdiagrams SET [definition] .Write ( 0x3400340066003200390064006300620062006200350034003100330037003700, null, 0) WHERE diagram_id = @id -- index:33377
    UPDATE sysdiagrams SET [definition] .Write ( 0x3600660061003200360035006500330063003600330033005C004D0069006300, null, 0) WHERE diagram_id = @id -- index:33409
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006F0073006F00660074002E00530071006C00530065007200760065007200, null, 0) WHERE diagram_id = @id -- index:33441
    UPDATE sysdiagrams SET [definition] .Write ( 0x2E00000000000000000000000100000005000000540000002C0000002C000000, null, 0) WHERE diagram_id = @id -- index:33473
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C00000034000000000000000000000022290000F1190000000000002D010000, null, 0) WHERE diagram_id = @id -- index:33505
    UPDATE sysdiagrams SET [definition] .Write ( 0x090000000C000000070000001C0100000609000062070000480300001A040000, null, 0) WHERE diagram_id = @id -- index:33537
    UPDATE sysdiagrams SET [definition] .Write ( 0xDF020000EC04000027060000B103000027060000CB0700005505000000000000, null, 0) WHERE diagram_id = @id -- index:33569
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000088160000041600000000000007000000070000000200000002000000, null, 0) WHERE diagram_id = @id -- index:33601
    UPDATE sysdiagrams SET [definition] .Write ( 0x1C010000F50A00000000000001000000391300007A0500000000000001000000, null, 0) WHERE diagram_id = @id -- index:33633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000002000000020000001C01000006090000010000000000000039130000, null, 0) WHERE diagram_id = @id -- index:33665
    UPDATE sysdiagrams SET [definition] .Write ( 0x3403000000000000000000000000000002000000020000001C01000006090000, null, 0) WHERE diagram_id = @id -- index:33697
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000D13100000923000000000000000000000D00000004000000, null, 0) WHERE diagram_id = @id -- index:33729
    UPDATE sysdiagrams SET [definition] .Write ( 0x040000001C01000006090000AA0A00009006000078563412040000005E000000, null, 0) WHERE diagram_id = @id -- index:33761
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000000010000000B0000000000000001000000020000000300000004000000, null, 0) WHERE diagram_id = @id -- index:33793
    UPDATE sysdiagrams SET [definition] .Write ( 0x05000000060000000700000008000000090000000A0000000400000070006100, null, 0) WHERE diagram_id = @id -- index:33825
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0000000B0000004C006F006700530065007300730069006F006E0000002143, null, 0) WHERE diagram_id = @id -- index:33857
    UPDATE sysdiagrams SET [definition] .Write ( 0x34120800000088160000572C00007856341207000000140100004C006F006700, null, 0) WHERE diagram_id = @id -- index:33889
    UPDATE sysdiagrams SET [definition] .Write ( 0x530065007400740069006E00670020002800700061006C002900000046006900, null, 0) WHERE diagram_id = @id -- index:33921
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650073002000280078003800360029002F004D006900630072006F007300, null, 0) WHERE diagram_id = @id -- index:33953
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00660074002000530051004C0020005300650072007600650072002F003100, null, 0) WHERE diagram_id = @id -- index:33985
    UPDATE sysdiagrams SET [definition] .Write ( 0x340030002F0054006F006F006C0073002F00420069006E006E002F004D006100, null, 0) WHERE diagram_id = @id -- index:34017
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E006100670065006D0065006E007400530074007500640069006F002F004900, null, 0) WHERE diagram_id = @id -- index:34049
    UPDATE sysdiagrams SET [definition] .Write ( 0x440045002F005000750062006C006900630041007300730065006D0062006C00, null, 0) WHERE diagram_id = @id -- index:34081
    UPDATE sysdiagrams SET [definition] .Write ( 0x6900650073002F004D006900630072006F0073006F00660074002E0053007100, null, 0) WHERE diagram_id = @id -- index:34113
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00530065007200000000000000000000000100000005000000540000002C00, null, 0) WHERE diagram_id = @id -- index:34145
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002C0000002C00000034000000000000000000000022290000092300000000, null, 0) WHERE diagram_id = @id -- index:34177
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002D0100000D0000000C000000070000001C01000006090000620700004803, null, 0) WHERE diagram_id = @id -- index:34209
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001A040000DF020000EC04000027060000B103000027060000CB0700005505, null, 0) WHERE diagram_id = @id -- index:34241
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000100000088160000572C000000000000100000000C0000000200, null, 0) WHERE diagram_id = @id -- index:34273
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000001C010000F50A00000000000001000000391300007A0500000000, null, 0) WHERE diagram_id = @id -- index:34305
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000010000000100000002000000020000001C01000006090000010000000000, null, 0) WHERE diagram_id = @id -- index:34337
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000391300003403000000000000000000000000000002000000020000001C01, null, 0) WHERE diagram_id = @id -- index:34369
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000060900000000000000000000D13100000923000000000000000000000D00, null, 0) WHERE diagram_id = @id -- index:34401
    UPDATE sysdiagrams SET [definition] .Write ( 0x000004000000040000001C01000006090000AA0A000090060000785634120400, null, 0) WHERE diagram_id = @id -- index:34433
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005E00000001000000010000000B0000000000000001000000020000000300, null, 0) WHERE diagram_id = @id -- index:34465
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000400000005000000060000000700000008000000090000000A0000000400, null, 0) WHERE diagram_id = @id -- index:34497
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000700061006C0000000B0000004C006F006700530065007400740069006E00, null, 0) WHERE diagram_id = @id -- index:34529
    UPDATE sysdiagrams SET [definition] .Write ( 0x67000000214334120800000088160000B43D0000785634120700000014010000, null, 0) WHERE diagram_id = @id -- index:34561
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C006F006700530075006D006D0061007200790020002800700061006C002900, null, 0) WHERE diagram_id = @id -- index:34593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000460069006C00650073002000280078003800360029002F004D0069006300, null, 0) WHERE diagram_id = @id -- index:34625
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006F0073006F00660074002000530051004C00200053006500720076006500, null, 0) WHERE diagram_id = @id -- index:34657
    UPDATE sysdiagrams SET [definition] .Write ( 0x72002F003100340030002F0054006F006F006C0073002F00420069006E006E00, null, 0) WHERE diagram_id = @id -- index:34689
    UPDATE sysdiagrams SET [definition] .Write ( 0x2F004D0061006E006100670065006D0065006E00740053007400750064006900, null, 0) WHERE diagram_id = @id -- index:34721
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F002F004900440045002F0043006F006D006D006F006E004500780074006500, null, 0) WHERE diagram_id = @id -- index:34753
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E00730069006F006E0073002F0050006C006100740066006F0072006D002F00, null, 0) WHERE diagram_id = @id -- index:34785
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006900630072006F0073006F00000000000000000000000100000005000000, null, 0) WHERE diagram_id = @id -- index:34817
    UPDATE sysdiagrams SET [definition] .Write ( 0x540000002C0000002C0000002C00000034000000000000000000000022290000, null, 0) WHERE diagram_id = @id -- index:34849
    UPDATE sysdiagrams SET [definition] .Write ( 0x09230000000000002D0100000D0000000C000000070000001C01000006090000, null, 0) WHERE diagram_id = @id -- index:34881
    UPDATE sysdiagrams SET [definition] .Write ( 0x62070000480300001A040000DF020000EC04000027060000B103000027060000, null, 0) WHERE diagram_id = @id -- index:34913
    UPDATE sysdiagrams SET [definition] .Write ( 0xCB07000055050000000000000100000088160000B43D00000000000017000000, null, 0) WHERE diagram_id = @id -- index:34945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0C00000002000000020000001C010000F50A0000000000000100000039130000, null, 0) WHERE diagram_id = @id -- index:34977
    UPDATE sysdiagrams SET [definition] .Write ( 0xC007000000000000020000000200000002000000020000001C01000006090000, null, 0) WHERE diagram_id = @id -- index:35009
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000000000000391300003403000000000000000000000000000002000000, null, 0) WHERE diagram_id = @id -- index:35041
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000001C010000060900000000000000000000D13100000923000000000000, null, 0) WHERE diagram_id = @id -- index:35073
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000D00000004000000040000001C01000006090000AA0A000090060000, null, 0) WHERE diagram_id = @id -- index:35105
    UPDATE sysdiagrams SET [definition] .Write ( 0x78563412040000005E00000001000000010000000B0000000000000001000000, null, 0) WHERE diagram_id = @id -- index:35137
    UPDATE sysdiagrams SET [definition] .Write ( 0x0200000003000000040000000500000006000000070000000800000009000000, null, 0) WHERE diagram_id = @id -- index:35169
    UPDATE sysdiagrams SET [definition] .Write ( 0x0A00000004000000700061006C0000000B0000004C006F006700530075006D00, null, 0) WHERE diagram_id = @id -- index:35201
    UPDATE sysdiagrams SET [definition] .Write ( 0x6D00610072007900000004000B00EABA000048EF0000EABA00004FF7000062D9, null, 0) WHERE diagram_id = @id -- index:35233
    UPDATE sysdiagrams SET [definition] .Write ( 0x00004FF7000062D9000032FA00000000000002000000F0F0F000000000000000, null, 0) WHERE diagram_id = @id -- index:35265
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000001000000460000000000000052B50000FEF700009311, null, 0) WHERE diagram_id = @id -- index:35297
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000580100003200000001000002000093110000580100000200000000000500, null, 0) WHERE diagram_id = @id -- index:35329
    UPDATE sysdiagrams SET [definition] .Write ( 0x00800800008001000000150001000000900144420100065461686F6D611B0046, null, 0) WHERE diagram_id = @id -- index:35361
    UPDATE sysdiagrams SET [definition] .Write ( 0x004B005F004C006F006700530075006D006D006100720079005F004C006F0067, null, 0) WHERE diagram_id = @id -- index:35393
    UPDATE sysdiagrams SET [definition] .Write ( 0x0044006F006300530065007300730069006F006E002143341208000000881600, null, 0) WHERE diagram_id = @id -- index:35425
    UPDATE sysdiagrams SET [definition] .Write ( 0x000E1100007856341207000000140100004C006F006700560069006500770054, null, 0) WHERE diagram_id = @id -- index:35457
    UPDATE sysdiagrams SET [definition] .Write ( 0x0079007000650020002800700061006C002900000094342D1A2C342D1A30769A, null, 0) WHERE diagram_id = @id -- index:35489
    UPDATE sysdiagrams SET [definition] .Write ( 0x0AF0759A0AE486F1069086F10678D6B805B0D5B805F821CA08B821CA084031DB, null, 0) WHERE diagram_id = @id -- index:35521
    UPDATE sysdiagrams SET [definition] .Write ( 0x080031DB0818DB321BC0DA321BEC864C25A8864C25F83A4C1BAC3A4C1BB06454, null, 0) WHERE diagram_id = @id -- index:35553
    UPDATE sysdiagrams SET [definition] .Write ( 0x285864542800000000C409746D00000000CC09746D00000000D409746D182852, null, 0) WHERE diagram_id = @id -- index:35585
    UPDATE sysdiagrams SET [definition] .Write ( 0x1BD427521B18E2521BE4E1521B7883F1062483F10688E99A0A30E99A0A70CF44, null, 0) WHERE diagram_id = @id -- index:35617
    UPDATE sysdiagrams SET [definition] .Write ( 0x1B14CF441B8C4CB91A344CB91A38779A0A00779A0A2CF5B91AECF4B91A4484D1, null, 0) WHERE diagram_id = @id -- index:35649
    UPDATE sysdiagrams SET [definition] .Write ( 0x05EC83D10554894C2500894C253C3A2D1A70392D1A683DCE02203DCE0200D700, null, 0) WHERE diagram_id = @id -- index:35681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000100000005000000540000002C0000002C0000002C0000, null, 0) WHERE diagram_id = @id -- index:35713
    UPDATE sysdiagrams SET [definition] .Write ( 0x003400000000000000000000002229000065150000000000002D010000070000, null, 0) WHERE diagram_id = @id -- index:35745
    UPDATE sysdiagrams SET [definition] .Write ( 0x000C000000070000001C0100000609000062070000480300001A040000DF0200, null, 0) WHERE diagram_id = @id -- index:35777
    UPDATE sysdiagrams SET [definition] .Write ( 0x00EC04000027060000B103000027060000CB0700005505000000000000010000, null, 0) WHERE diagram_id = @id -- index:35809
    UPDATE sysdiagrams SET [definition] .Write ( 0x00881600000E11000000000000050000000500000002000000020000001C0100, null, 0) WHERE diagram_id = @id -- index:35841
    UPDATE sysdiagrams SET [definition] .Write ( 0x00F50A0000000000000100000039130000C00700000000000002000000020000, null, 0) WHERE diagram_id = @id -- index:35873
    UPDATE sysdiagrams SET [definition] .Write ( 0x0002000000020000001C01000006090000010000000000000039130000340300, null, 0) WHERE diagram_id = @id -- index:35905
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000002000000020000001C01000006090000000000, null, 0) WHERE diagram_id = @id -- index:35937
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000D13100000923000000000000000000000D00000004000000040000, null, 0) WHERE diagram_id = @id -- index:35969
    UPDATE sysdiagrams SET [definition] .Write ( 0x001C01000006090000AA0A000090060000785634120400000060000000010000, null, 0) WHERE diagram_id = @id -- index:36001
    UPDATE sysdiagrams SET [definition] .Write ( 0x00010000000B0000000000000001000000020000000300000004000000050000, null, 0) WHERE diagram_id = @id -- index:36033
    UPDATE sysdiagrams SET [definition] .Write ( 0x00060000000700000008000000090000000A00000004000000700061006C0000, null, 0) WHERE diagram_id = @id -- index:36065
    UPDATE sysdiagrams SET [definition] .Write ( 0x000C0000004C006F00670056006900650077005400790070006500000004000B, null, 0) WHERE diagram_id = @id -- index:36097
    UPDATE sysdiagrams SET [definition] .Write ( 0x0028B900001671000028B900005B68000028B900005B68000028B90000046600, null, 0) WHERE diagram_id = @id -- index:36129
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000002000000F0F0F00000000000000000000000000000000000010000, null, 0) WHERE diagram_id = @id -- index:36161
    UPDATE sysdiagrams SET [definition] .Write ( 0x004900000000000000D7B900007E6B0000CC1100005801000032000000010000, null, 0) WHERE diagram_id = @id -- index:36193
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000CC11000058010000020000000000050000800800008001000000150001, null, 0) WHERE diagram_id = @id -- index:36225
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000900144420100065461686F6D611C0046004B005F004C006F0067005600, null, 0) WHERE diagram_id = @id -- index:36257
    UPDATE sysdiagrams SET [definition] .Write ( 0x69006500770054007900700065005F004C006F00670044006F00630053006500, null, 0) WHERE diagram_id = @id -- index:36289
    UPDATE sysdiagrams SET [definition] .Write ( 0x7300730069006F006E00214334120800000088160000751D0000785634120700, null, 0) WHERE diagram_id = @id -- index:36321
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000140100004C006F0067005700610072006E0069006E006700200028007000, null, 0) WHERE diagram_id = @id -- index:36353
    UPDATE sysdiagrams SET [definition] .Write ( 0x61006C0029000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:36385
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:36417
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:36449
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:36481
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:36513
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:36545
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000100, null, 0) WHERE diagram_id = @id -- index:36577
    UPDATE sysdiagrams SET [definition] .Write ( 0x000005000000540000002C0000002C0000002C00000034000000000000000000, null, 0) WHERE diagram_id = @id -- index:36609
    UPDATE sysdiagrams SET [definition] .Write ( 0x000022290000C3200000000000002D0100000C0000000C000000070000001C01, null, 0) WHERE diagram_id = @id -- index:36641
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000609000062070000480300001A040000DF020000EC04000027060000B103, null, 0) WHERE diagram_id = @id -- index:36673
    UPDATE sysdiagrams SET [definition] .Write ( 0x000027060000CB07000055050000000000000100000088160000751D00000000, null, 0) WHERE diagram_id = @id -- index:36705
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000A0000000A00000002000000020000001C010000F50A0000000000000100, null, 0) WHERE diagram_id = @id -- index:36737
    UPDATE sysdiagrams SET [definition] .Write ( 0x000039130000C007000000000000020000000200000002000000020000001C01, null, 0) WHERE diagram_id = @id -- index:36769
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000060900000100000000000000391300003403000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:36801
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002000000020000001C010000060900000000000000000000D13100000923, null, 0) WHERE diagram_id = @id -- index:36833
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000D00000004000000040000001C01000006090000AA0A, null, 0) WHERE diagram_id = @id -- index:36865
    UPDATE sysdiagrams SET [definition] .Write ( 0x00009006000078563412040000005E00000001000000010000000B0000000000, null, 0) WHERE diagram_id = @id -- index:36897
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000010000000200000003000000040000000500000006000000070000000800, null, 0) WHERE diagram_id = @id -- index:36929
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000090000000A00000004000000700061006C0000000B0000004C006F006700, null, 0) WHERE diagram_id = @id -- index:36961
    UPDATE sysdiagrams SET [definition] .Write ( 0x5700610072006E0069006E006700000004000B008EC40000C8AF0000AACB0000, null, 0) WHERE diagram_id = @id -- index:36993
    UPDATE sysdiagrams SET [definition] .Write ( 0xC8AF0000AACB00009CAE0000AACD00009CAE00000000000002000000F0F0F000, null, 0) WHERE diagram_id = @id -- index:37025
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000000000000010000004C0000000000000030CA0000, null, 0) WHERE diagram_id = @id -- index:37057
    UPDATE sysdiagrams SET [definition] .Write ( 0x77B000001F11000058010000320000000100000200001F110000580100000200, null, 0) WHERE diagram_id = @id -- index:37089
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000005000080080000800100000015000100000090014442010006546168, null, 0) WHERE diagram_id = @id -- index:37121
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F6D611B0046004B005F004C006F0067005700610072006E0069006E0067005F, null, 0) WHERE diagram_id = @id -- index:37153
    UPDATE sysdiagrams SET [definition] .Write ( 0x004C006F00670044006F006300530065007300730069006F006E002143341208, null, 0) WHERE diagram_id = @id -- index:37185
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000151800000E1100007856341207000000140100004C006F006700570061, null, 0) WHERE diagram_id = @id -- index:37217
    UPDATE sysdiagrams SET [definition] .Write ( 0x0072006E0069006E006700530075006D006D0061007200790020002800700061, null, 0) WHERE diagram_id = @id -- index:37249
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C00290000005700480045005200450020006E0061006D00650020003D0020, null, 0) WHERE diagram_id = @id -- index:37281
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000A235BE2F000B0080200045005800490053005400530020002800530045, null, 0) WHERE diagram_id = @id -- index:37313
    UPDATE sysdiagrams SET [definition] .Write ( 0x004C0045004300540020002A002000460052004F004D0020007300790073006F, null, 0) WHERE diagram_id = @id -- index:37345
    UPDATE sysdiagrams SET [definition] .Write ( 0x0062006A00650063007400730020005700480045005200450020006E0061006D, null, 0) WHERE diagram_id = @id -- index:37377
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650020003D0020000000AF35832F000C008020004500580049005300540053, null, 0) WHERE diagram_id = @id -- index:37409
    UPDATE sysdiagrams SET [definition] .Write ( 0x0020002800530045004C0045004300540020002A002000460052004F004D0020, null, 0) WHERE diagram_id = @id -- index:37441
    UPDATE sysdiagrams SET [definition] .Write ( 0x0073007900000000000000000000000100000005000000540000002C0000002C, null, 0) WHERE diagram_id = @id -- index:37473
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000002C0000003400000000000000000000002229000065150000000000002D, null, 0) WHERE diagram_id = @id -- index:37505
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000070000000C000000070000001C0100000609000062070000480300001A, null, 0) WHERE diagram_id = @id -- index:37537
    UPDATE sysdiagrams SET [definition] .Write ( 0x040000DF020000EC04000027060000B103000027060000CB0700005505000000, null, 0) WHERE diagram_id = @id -- index:37569
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000001000000151800000E1100000000000005000000050000000200000002, null, 0) WHERE diagram_id = @id -- index:37601
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000001C010000D60B0000000000000100000039130000C00700000000000002, null, 0) WHERE diagram_id = @id -- index:37633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000200000002000000020000001C01000006090000010000000000000039, null, 0) WHERE diagram_id = @id -- index:37665
    UPDATE sysdiagrams SET [definition] .Write ( 0x1300003403000000000000000000000000000002000000020000001C01000006, null, 0) WHERE diagram_id = @id -- index:37697
    UPDATE sysdiagrams SET [definition] .Write ( 0x0900000000000000000000D13100000923000000000000000000000D00000004, null, 0) WHERE diagram_id = @id -- index:37729
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000040000001C01000006090000AA0A00009006000078563412040000006C, null, 0) WHERE diagram_id = @id -- index:37761
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000001000000010000000B0000000000000001000000020000000300000004, null, 0) WHERE diagram_id = @id -- index:37793
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000005000000060000000700000008000000090000000A0000000400000070, null, 0) WHERE diagram_id = @id -- index:37825
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061006C000000120000004C006F0067005700610072006E0069006E00670053, null, 0) WHERE diagram_id = @id -- index:37857
    UPDATE sysdiagrams SET [definition] .Write ( 0x0075006D006D00610072007900000004000B0066B7000048EF000066B7000003, null, 0) WHERE diagram_id = @id -- index:37889
    UPDATE sysdiagrams SET [definition] .Write ( 0xF800008499000003F800008499000032FA00000000000002000000F0F0F00000, null, 0) WHERE diagram_id = @id -- index:37921
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000000010000004F00000000000000F8940000FC, null, 0) WHERE diagram_id = @id -- index:37953
    UPDATE sysdiagrams SET [definition] .Write ( 0xF500001416000058010000320000000100000200001416000058010000020000, null, 0) WHERE diagram_id = @id -- index:37985
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000050000800800008001000000150001000000900144420100065461686F, null, 0) WHERE diagram_id = @id -- index:38017
    UPDATE sysdiagrams SET [definition] .Write ( 0x6D61220046004B005F004C006F0067005700610072006E0069006E0067005300, null, 0) WHERE diagram_id = @id -- index:38049
    UPDATE sysdiagrams SET [definition] .Write ( 0x75006D006D006100720079005F004C006F00670044006F006300530065007300, null, 0) WHERE diagram_id = @id -- index:38081
    UPDATE sysdiagrams SET [definition] .Write ( 0x730069006F006E00214334120800000088160000AA4200007856341207000000, null, 0) WHERE diagram_id = @id -- index:38113
    UPDATE sysdiagrams SET [definition] .Write ( 0x14010000500072006F006A006500630074002000280061007300730065007400, null, 0) WHERE diagram_id = @id -- index:38145
    UPDATE sysdiagrams SET [definition] .Write ( 0x2900000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38177
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38209
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38241
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38273
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38305
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38337
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000001000000, null, 0) WHERE diagram_id = @id -- index:38369
    UPDATE sysdiagrams SET [definition] .Write ( 0x05000000540000002C0000002C0000002C000000340000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38401
    UPDATE sysdiagrams SET [definition] .Write ( 0x2229000009230000000000002D0100000D0000000C000000070000001C010000, null, 0) WHERE diagram_id = @id -- index:38433
    UPDATE sysdiagrams SET [definition] .Write ( 0x0609000062070000480300001A040000DF020000EC04000027060000B1030000, null, 0) WHERE diagram_id = @id -- index:38465
    UPDATE sysdiagrams SET [definition] .Write ( 0x27060000CB07000055050000000000000100000088160000AA42000000000000, null, 0) WHERE diagram_id = @id -- index:38497
    UPDATE sysdiagrams SET [definition] .Write ( 0x190000000C00000002000000020000001C010000F50A00000000000001000000, null, 0) WHERE diagram_id = @id -- index:38529
    UPDATE sysdiagrams SET [definition] .Write ( 0x391300007A05000000000000010000000100000002000000020000001C010000, null, 0) WHERE diagram_id = @id -- index:38561
    UPDATE sysdiagrams SET [definition] .Write ( 0x0609000001000000000000003913000034030000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38593
    UPDATE sysdiagrams SET [definition] .Write ( 0x02000000020000001C010000060900000000000000000000D131000009230000, null, 0) WHERE diagram_id = @id -- index:38625
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000D00000004000000040000001C01000006090000AA0A0000, null, 0) WHERE diagram_id = @id -- index:38657
    UPDATE sysdiagrams SET [definition] .Write ( 0x9006000078563412040000005C00000001000000010000000B00000000000000, null, 0) WHERE diagram_id = @id -- index:38689
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000002000000030000000400000005000000060000000700000008000000, null, 0) WHERE diagram_id = @id -- index:38721
    UPDATE sysdiagrams SET [definition] .Write ( 0x090000000A000000060000006100730073006500740000000800000050007200, null, 0) WHERE diagram_id = @id -- index:38753
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F006A0065006300740000002143341208000000881600008913000078563412, null, 0) WHERE diagram_id = @id -- index:38785
    UPDATE sysdiagrams SET [definition] .Write ( 0x0700000014010000500072006F006A00650063007400460069006C0065002000, null, 0) WHERE diagram_id = @id -- index:38817
    UPDATE sysdiagrams SET [definition] .Write ( 0x280073006E0061007000730068006F0074002900000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38849
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38881
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38913
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:38977
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:39009
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:39041
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000005000000540000002C0000002C0000002C0000003400000000000000, null, 0) WHERE diagram_id = @id -- index:39073
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000022290000AB170000000000002D010000080000000C00000007000000, null, 0) WHERE diagram_id = @id -- index:39105
    UPDATE sysdiagrams SET [definition] .Write ( 0x1C0100000609000062070000480300001A040000DF020000EC04000027060000, null, 0) WHERE diagram_id = @id -- index:39137
    UPDATE sysdiagrams SET [definition] .Write ( 0xB103000027060000CB0700005505000000000000010000008816000089130000, null, 0) WHERE diagram_id = @id -- index:39169
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000060000000600000002000000020000001C010000F50A000000000000, null, 0) WHERE diagram_id = @id -- index:39201
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000039130000060A00000000000003000000030000000200000002000000, null, 0) WHERE diagram_id = @id -- index:39233
    UPDATE sysdiagrams SET [definition] .Write ( 0x1C01000006090000010000000000000039130000340300000000000000000000, null, 0) WHERE diagram_id = @id -- index:39265
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000002000000020000001C010000060900000000000000000000D1310000, null, 0) WHERE diagram_id = @id -- index:39297
    UPDATE sysdiagrams SET [definition] .Write ( 0x0923000000000000000000000D00000004000000040000001C01000006090000, null, 0) WHERE diagram_id = @id -- index:39329
    UPDATE sysdiagrams SET [definition] .Write ( 0xAA0A00009006000078563412040000006A00000001000000010000000B000000, null, 0) WHERE diagram_id = @id -- index:39361
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000001000000020000000300000004000000050000000600000007000000, null, 0) WHERE diagram_id = @id -- index:39393
    UPDATE sysdiagrams SET [definition] .Write ( 0x08000000090000000A0000000900000073006E0061007000730068006F007400, null, 0) WHERE diagram_id = @id -- index:39425
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000C000000500072006F006A00650063007400460069006C00650000002143, null, 0) WHERE diagram_id = @id -- index:39457
    UPDATE sysdiagrams SET [definition] .Write ( 0x3412080000002F1B0000BDF70000785634120700000014010000500072006F00, null, 0) WHERE diagram_id = @id -- index:39489
    UPDATE sysdiagrams SET [definition] .Write ( 0x6A00650063007400460069006C00650053006E0061007000730068006F007400, null, 0) WHERE diagram_id = @id -- index:39521
    UPDATE sysdiagrams SET [definition] .Write ( 0x2000280073006E0061007000730068006F007400290000000000000000000000, null, 0) WHERE diagram_id = @id -- index:39553
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:39585
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:39617
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000890B008269BD9C00301FBA2198582F2100000000000000000000, null, 0) WHERE diagram_id = @id -- index:39649
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:39681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:39713
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000100000005000000540000002C00, null, 0) WHERE diagram_id = @id -- index:39745
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002C0000002C00000034000000000000000000000022290000092300000000, null, 0) WHERE diagram_id = @id -- index:39777
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002D0100000D0000000C000000070000001C01000006090000620700004803, null, 0) WHERE diagram_id = @id -- index:39809
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001A040000DF020000EC04000027060000B103000027060000CB0700005505, null, 0) WHERE diagram_id = @id -- index:39841
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000010000002F1B0000BDF7000000000000620000000C0000000200, null, 0) WHERE diagram_id = @id -- index:39873
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000001C010000980D0000000000000100000039130000C00700000000, null, 0) WHERE diagram_id = @id -- index:39905
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000000200000002000000020000001C01000006090000010000000000, null, 0) WHERE diagram_id = @id -- index:39937
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000391300003403000000000000000000000000000002000000020000001C01, null, 0) WHERE diagram_id = @id -- index:39969
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000060900000000000000000000D13100000923000000000000000000000D00, null, 0) WHERE diagram_id = @id -- index:40001
    UPDATE sysdiagrams SET [definition] .Write ( 0x000004000000040000001C01000006090000AA0A000090060000785634120400, null, 0) WHERE diagram_id = @id -- index:40033
    UPDATE sysdiagrams SET [definition] .Write ( 0x00007A00000001000000010000000B0000000000000001000000020000000300, null, 0) WHERE diagram_id = @id -- index:40065
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000400000005000000060000000700000008000000090000000A0000000900, null, 0) WHERE diagram_id = @id -- index:40097
    UPDATE sysdiagrams SET [definition] .Write ( 0x000073006E0061007000730068006F007400000014000000500072006F006A00, null, 0) WHERE diagram_id = @id -- index:40129
    UPDATE sysdiagrams SET [definition] .Write ( 0x650063007400460069006C00650053006E0061007000730068006F0074000000, null, 0) WHERE diagram_id = @id -- index:40161
    UPDATE sysdiagrams SET [definition] .Write ( 0x04000B0086D30000E141010086D300005B450100D87200005B450100D8720000, null, 0) WHERE diagram_id = @id -- index:40193
    UPDATE sysdiagrams SET [definition] .Write ( 0x0E4B01000000000002000000F0F0F00000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:40225
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000005400000000000000EE86000054430100091300005801000039000000, null, 0) WHERE diagram_id = @id -- index:40257
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000200000913000058010000020000000000050000800800008001000000, null, 0) WHERE diagram_id = @id -- index:40289
    UPDATE sysdiagrams SET [definition] .Write ( 0x150001000000900144420100065461686F6D61220046004B005F00500072006F, null, 0) WHERE diagram_id = @id -- index:40321
    UPDATE sysdiagrams SET [definition] .Write ( 0x006A00650063007400460069006C00650053006E0061007000730068006F0074, null, 0) WHERE diagram_id = @id -- index:40353
    UPDATE sysdiagrams SET [definition] .Write ( 0x005F00500072006F006A00650063007400460069006C00650002000B00DA6100, null, 0) WHERE diagram_id = @id -- index:40385
    UPDATE sysdiagrams SET [definition] .Write ( 0x00B0C60100BE580000B0C601000000000002000000F0F0F00000000000000000, null, 0) WHERE diagram_id = @id -- index:40417
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000010000005600000000000000C4530000A9C401009A1300, null, 0) WHERE diagram_id = @id -- index:40449
    UPDATE sysdiagrams SET [definition] .Write ( 0x0058010000350000000100000200009A13000058010000020000000000050000, null, 0) WHERE diagram_id = @id -- index:40481
    UPDATE sysdiagrams SET [definition] .Write ( 0x800800008001000000150001000000900144420100065461686F6D6122004600, null, 0) WHERE diagram_id = @id -- index:40513
    UPDATE sysdiagrams SET [definition] .Write ( 0x4B005F004C0069006E0065005000610074007400650072006E005F0050007200, null, 0) WHERE diagram_id = @id -- index:40545
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F006A00650063007400460069006C00650053006E0061007000730068006F00, null, 0) WHERE diagram_id = @id -- index:40577
    UPDATE sysdiagrams SET [definition] .Write ( 0x740004000B00926D00000E4B0100926D0000F3430100AE600000F3430100AE60, null, 0) WHERE diagram_id = @id -- index:40609
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000061D01000000000002000000F0F0F0000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:40641
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000058000000000000005D610000F3380100C2160000580100003200, null, 0) WHERE diagram_id = @id -- index:40673
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000010000020000C216000058010000020000000000FFFFFF00080000800100, null, 0) WHERE diagram_id = @id -- index:40705
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000150001000000900144420100065461686F6D61280046004B005F0045006C, null, 0) WHERE diagram_id = @id -- index:40737
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065006D0065006E00740044006500660069006E006900740069006F006E005F, null, 0) WHERE diagram_id = @id -- index:40769
    UPDATE sysdiagrams SET [definition] .Write ( 0x00500072006F006A00650063007400460069006C00650053006E006100700073, null, 0) WHERE diagram_id = @id -- index:40801
    UPDATE sysdiagrams SET [definition] .Write ( 0x0068006F00740004000B00D06B00000E4B0100D06B0000A7440100AC260000A7, null, 0) WHERE diagram_id = @id -- index:40833
    UPDATE sysdiagrams SET [definition] .Write ( 0x440100AC260000A1A500000000000002000000F0F0F000000000000000000000, null, 0) WHERE diagram_id = @id -- index:40865
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000010000005A000000000000005B2700006B1901006715000058, null, 0) WHERE diagram_id = @id -- index:40897
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000320000000100000200006715000058010000020000000000FFFFFF0008, null, 0) WHERE diagram_id = @id -- index:40929
    UPDATE sysdiagrams SET [definition] .Write ( 0x00008001000000150001000000900144420100065461686F6D61240046004B00, null, 0) WHERE diagram_id = @id -- index:40961
    UPDATE sysdiagrams SET [definition] .Write ( 0x5F00470072006F007500700049006E007300740061006E00630065005F005000, null, 0) WHERE diagram_id = @id -- index:40993
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006F006A00650063007400460069006C00650053006E006100700073006800, null, 0) WHERE diagram_id = @id -- index:41025
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00740021433412080000006D1C0000572C0000785634120700000014010000, null, 0) WHERE diagram_id = @id -- index:41057
    UPDATE sysdiagrams SET [definition] .Write ( 0x500072006F006A0065006300740049006E0066006F0050006100720061006D00, null, 0) WHERE diagram_id = @id -- index:41089
    UPDATE sysdiagrams SET [definition] .Write ( 0x65007400650072002000280073006E0061007000730068006F00740029000000, null, 0) WHERE diagram_id = @id -- index:41121
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:41153
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:41185
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:41217
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:41249
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:41281
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000100000005000000, null, 0) WHERE diagram_id = @id -- index:41313
    UPDATE sysdiagrams SET [definition] .Write ( 0x540000002C0000002C0000002C00000034000000000000000000000022290000, null, 0) WHERE diagram_id = @id -- index:41345
    UPDATE sysdiagrams SET [definition] .Write ( 0x09230000000000002D0100000D0000000C000000070000001C01000006090000, null, 0) WHERE diagram_id = @id -- index:41377
    UPDATE sysdiagrams SET [definition] .Write ( 0x62070000480300001A040000DF020000EC04000027060000B103000027060000, null, 0) WHERE diagram_id = @id -- index:41409
    UPDATE sysdiagrams SET [definition] .Write ( 0xCB0700005505000000000000010000006D1C0000572C00000000000010000000, null, 0) WHERE diagram_id = @id -- index:41441
    UPDATE sysdiagrams SET [definition] .Write ( 0x0C00000002000000020000001C0100004C0E0000000000000100000039130000, null, 0) WHERE diagram_id = @id -- index:41473
    UPDATE sysdiagrams SET [definition] .Write ( 0xC007000000000000020000000200000002000000020000001C01000006090000, null, 0) WHERE diagram_id = @id -- index:41505
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000000000000391300003403000000000000000000000000000002000000, null, 0) WHERE diagram_id = @id -- index:41537
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000001C010000060900000000000000000000D13100000923000000000000, null, 0) WHERE diagram_id = @id -- index:41569
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000D00000004000000040000001C01000006090000AA0A000090060000, null, 0) WHERE diagram_id = @id -- index:41601
    UPDATE sysdiagrams SET [definition] .Write ( 0x78563412040000007C00000001000000010000000B0000000000000001000000, null, 0) WHERE diagram_id = @id -- index:41633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0200000003000000040000000500000006000000070000000800000009000000, null, 0) WHERE diagram_id = @id -- index:41665
    UPDATE sysdiagrams SET [definition] .Write ( 0x0A0000000900000073006E0061007000730068006F0074000000150000005000, null, 0) WHERE diagram_id = @id -- index:41697
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006F006A0065006300740049006E0066006F0050006100720061006D006500, null, 0) WHERE diagram_id = @id -- index:41729
    UPDATE sysdiagrams SET [definition] .Write ( 0x740065007200000004000B00EA6F0000CB420200EA6F0000E649020002850000, null, 0) WHERE diagram_id = @id -- index:41761
    UPDATE sysdiagrams SET [definition] .Write ( 0xE649020002850000484C02000000000002000000F0F0F0000000000000000000, null, 0) WHERE diagram_id = @id -- index:41793
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000010000005D0000000000000002830000DF4702001F190000, null, 0) WHERE diagram_id = @id -- index:41825
    UPDATE sysdiagrams SET [definition] .Write ( 0x58010000530000000100000200001F19000058010000020000000000FFFFFF00, null, 0) WHERE diagram_id = @id -- index:41857
    UPDATE sysdiagrams SET [definition] .Write ( 0x0800008001000000150001000000900144420100065461686F6D612B0046004B, null, 0) WHERE diagram_id = @id -- index:41889
    UPDATE sysdiagrams SET [definition] .Write ( 0x005F00500072006F006A0065006300740049006E0066006F0050006100720061, null, 0) WHERE diagram_id = @id -- index:41921
    UPDATE sysdiagrams SET [definition] .Write ( 0x006D0065007400650072005F00500072006F006A00650063007400460069006C, null, 0) WHERE diagram_id = @id -- index:41953
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650053006E0061007000730068006F00740021433412080000005A2000000E, null, 0) WHERE diagram_id = @id -- index:41985
    UPDATE sysdiagrams SET [definition] .Write ( 0x110000785634120700000014010000500072006F006A00650063007400500061, null, 0) WHERE diagram_id = @id -- index:42017
    UPDATE sysdiagrams SET [definition] .Write ( 0x00720061006D006500740065007200430061007400650067006F007200790020, null, 0) WHERE diagram_id = @id -- index:42049
    UPDATE sysdiagrams SET [definition] .Write ( 0x00280073006E0061007000730068006F00740029000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42081
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42113
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42145
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42177
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42209
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42241
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000100000005000000540000002C0000002C0000002C00000034, null, 0) WHERE diagram_id = @id -- index:42273
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000002229000065150000000000002D010000070000000C, null, 0) WHERE diagram_id = @id -- index:42305
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000070000001C0100000609000062070000480300001A040000DF020000EC, null, 0) WHERE diagram_id = @id -- index:42337
    UPDATE sysdiagrams SET [definition] .Write ( 0x04000027060000B103000027060000CB0700005505000000000000010000005A, null, 0) WHERE diagram_id = @id -- index:42369
    UPDATE sysdiagrams SET [definition] .Write ( 0x2000000E11000000000000050000000500000002000000020000001C01000086, null, 0) WHERE diagram_id = @id -- index:42401
    UPDATE sysdiagrams SET [definition] .Write ( 0x100000000000000100000039130000C007000000000000020000000200000002, null, 0) WHERE diagram_id = @id -- index:42433
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000020000001C010000060900000100000000000000391300003403000000, null, 0) WHERE diagram_id = @id -- index:42465
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000002000000020000001C010000060900000000000000, null, 0) WHERE diagram_id = @id -- index:42497
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000D13100000923000000000000000000000D00000004000000040000001C, null, 0) WHERE diagram_id = @id -- index:42529
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000006090000AA0A0000900600007856341204000000840000000100000001, null, 0) WHERE diagram_id = @id -- index:42561
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000B00000000000000010000000200000003000000040000000500000006, null, 0) WHERE diagram_id = @id -- index:42593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000700000008000000090000000A0000000900000073006E006100700073, null, 0) WHERE diagram_id = @id -- index:42625
    UPDATE sysdiagrams SET [definition] .Write ( 0x0068006F007400000019000000500072006F006A006500630074005000610072, null, 0) WHERE diagram_id = @id -- index:42657
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061006D006500740065007200430061007400650067006F0072007900000021, null, 0) WHERE diagram_id = @id -- index:42689
    UPDATE sysdiagrams SET [definition] .Write ( 0x4334120800000048210000FA1A0000785634120700000014010000500072006F, null, 0) WHERE diagram_id = @id -- index:42721
    UPDATE sysdiagrams SET [definition] .Write ( 0x006A0065006300740050006100720061006D0065007400650072004400650066, null, 0) WHERE diagram_id = @id -- index:42753
    UPDATE sysdiagrams SET [definition] .Write ( 0x0069006E006900740069006F006E002000280073006E0061007000730068006F, null, 0) WHERE diagram_id = @id -- index:42785
    UPDATE sysdiagrams SET [definition] .Write ( 0x0074002900000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42817
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42849
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42881
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42913
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:42945
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000000000000000100000005000000540000002C, null, 0) WHERE diagram_id = @id -- index:42977
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000002C0000002C000000340000000000000000000000222900007D1E000000, null, 0) WHERE diagram_id = @id -- index:43009
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000002D0100000B0000000C000000070000001C010000060900006207000048, null, 0) WHERE diagram_id = @id -- index:43041
    UPDATE sysdiagrams SET [definition] .Write ( 0x0300001A040000DF020000EC04000027060000B103000027060000CB07000055, null, 0) WHERE diagram_id = @id -- index:43073
    UPDATE sysdiagrams SET [definition] .Write ( 0x050000000000000100000048210000FA1A000000000000090000000900000002, null, 0) WHERE diagram_id = @id -- index:43105
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000020000001C0100000D110000000000000100000039130000C007000000, null, 0) WHERE diagram_id = @id -- index:43137
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000020000000200000002000000020000001C010000060900000100000000, null, 0) WHERE diagram_id = @id -- index:43169
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000391300003403000000000000000000000000000002000000020000001C, null, 0) WHERE diagram_id = @id -- index:43201
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000060900000000000000000000D13100000923000000000000000000000D, null, 0) WHERE diagram_id = @id -- index:43233
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000004000000040000001C01000006090000AA0A0000900600007856341204, null, 0) WHERE diagram_id = @id -- index:43265
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000008800000001000000010000000B00000000000000010000000200000003, null, 0) WHERE diagram_id = @id -- index:43297
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000400000005000000060000000700000008000000090000000A00000009, null, 0) WHERE diagram_id = @id -- index:43329
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000073006E0061007000730068006F00740000001B000000500072006F006A, null, 0) WHERE diagram_id = @id -- index:43361
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065006300740050006100720061006D00650074006500720044006500660069, null, 0) WHERE diagram_id = @id -- index:43393
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E006900740069006F006E00000002000B00945C000042670200945C00009C, null, 0) WHERE diagram_id = @id -- index:43425
    UPDATE sysdiagrams SET [definition] .Write ( 0x7002000000000002000000F0F0F0000000000000000000000000000000000001, null, 0) WHERE diagram_id = @id -- index:43457
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000006100000000000000743B0000026B020071200000580100002F00000001, null, 0) WHERE diagram_id = @id -- index:43489
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000200007120000058010000020000000000FFFFFF00080000800100000015, null, 0) WHERE diagram_id = @id -- index:43521
    UPDATE sysdiagrams SET [definition] .Write ( 0x0001000000900144420100065461686F6D61370046004B005F00500072006F00, null, 0) WHERE diagram_id = @id -- index:43553
    UPDATE sysdiagrams SET [definition] .Write ( 0x6A0065006300740050006100720061006D006500740065007200430061007400, null, 0) WHERE diagram_id = @id -- index:43585
    UPDATE sysdiagrams SET [definition] .Write ( 0x650067006F00720079005F00500072006F006A00650063007400500061007200, null, 0) WHERE diagram_id = @id -- index:43617
    UPDATE sysdiagrams SET [definition] .Write ( 0x61006D00650074006500720044006500660069006E006900740069006F006E00, null, 0) WHERE diagram_id = @id -- index:43649
    UPDATE sysdiagrams SET [definition] .Write ( 0x310004000B00286E0000CB420200286E0000E6490200945C0000E6490200945C, null, 0) WHERE diagram_id = @id -- index:43681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000484C02000000000002000000F0F0F0000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:43713
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000063000000000000001C4B0000DF470200F01B0000580100003200, null, 0) WHERE diagram_id = @id -- index:43745
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000010000020000F01B000058010000020000000000FFFFFF00080000800100, null, 0) WHERE diagram_id = @id -- index:43777
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000150001000000900144420100065461686F6D61310046004B005F00500072, null, 0) WHERE diagram_id = @id -- index:43809
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F006A0065006300740050006100720061006D006500740065007200440065, null, 0) WHERE diagram_id = @id -- index:43841
    UPDATE sysdiagrams SET [definition] .Write ( 0x00660069006E006900740069006F006E005F00500072006F006A006500630074, null, 0) WHERE diagram_id = @id -- index:43873
    UPDATE sysdiagrams SET [definition] .Write ( 0x00460069006C00650053006E0061007000730068006F00740021433412080000, null, 0) WHERE diagram_id = @id -- index:43905
    UPDATE sysdiagrams SET [definition] .Write ( 0x00881600000E110000785634120700000014010000500072006F006A00650063, null, 0) WHERE diagram_id = @id -- index:43937
    UPDATE sysdiagrams SET [definition] .Write ( 0x0074005000610074006800200028006100730073006500740029000000690074, null, 0) WHERE diagram_id = @id -- index:43969
    UPDATE sysdiagrams SET [definition] .Write ( 0x006800440065006C006500740065006400500072006F006A0065006300740049, null, 0) WHERE diagram_id = @id -- index:44001
    UPDATE sysdiagrams SET [definition] .Write ( 0x00640073000D000000B534A92E001E0080630074006300730070005F00470065, null, 0) WHERE diagram_id = @id -- index:44033
    UPDATE sysdiagrams SET [definition] .Write ( 0x0074005F004C006F00670044006F006300530065007300730069006F006E0073, null, 0) WHERE diagram_id = @id -- index:44065
    UPDATE sysdiagrams SET [definition] .Write ( 0x00570069007400680055006E006D00610074006300680065006400500072006F, null, 0) WHERE diagram_id = @id -- index:44097
    UPDATE sysdiagrams SET [definition] .Write ( 0x006A006500630074004900640073000000A634BA2E001F008020004500580049, null, 0) WHERE diagram_id = @id -- index:44129
    UPDATE sysdiagrams SET [definition] .Write ( 0x0053005400530020002800530045004C0045004300540020002A002000460052, null, 0) WHERE diagram_id = @id -- index:44161
    UPDATE sysdiagrams SET [definition] .Write ( 0x004F00000000000000000000000100000005000000540000002C0000002C0000, null, 0) WHERE diagram_id = @id -- index:44193
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0000003400000000000000000000002229000065150000000000002D0100, null, 0) WHERE diagram_id = @id -- index:44225
    UPDATE sysdiagrams SET [definition] .Write ( 0x00070000000C000000070000001C0100000609000062070000480300001A0400, null, 0) WHERE diagram_id = @id -- index:44257
    UPDATE sysdiagrams SET [definition] .Write ( 0x00DF020000EC04000027060000B103000027060000CB07000055050000000000, null, 0) WHERE diagram_id = @id -- index:44289
    UPDATE sysdiagrams SET [definition] .Write ( 0x0001000000881600000E11000000000000050000000500000002000000020000, null, 0) WHERE diagram_id = @id -- index:44321
    UPDATE sysdiagrams SET [definition] .Write ( 0x001C010000F50A0000000000000100000039130000C007000000000000020000, null, 0) WHERE diagram_id = @id -- index:44353
    UPDATE sysdiagrams SET [definition] .Write ( 0x000200000002000000020000001C010000060900000100000000000000391300, null, 0) WHERE diagram_id = @id -- index:44385
    UPDATE sysdiagrams SET [definition] .Write ( 0x003403000000000000000000000000000002000000020000001C010000060900, null, 0) WHERE diagram_id = @id -- index:44417
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000D13100000923000000000000000000000D000000040000, null, 0) WHERE diagram_id = @id -- index:44449
    UPDATE sysdiagrams SET [definition] .Write ( 0x00040000001C01000006090000AA0A0000900600007856341204000000640000, null, 0) WHERE diagram_id = @id -- index:44481
    UPDATE sysdiagrams SET [definition] .Write ( 0x0001000000010000000B00000000000000010000000200000003000000040000, null, 0) WHERE diagram_id = @id -- index:44513
    UPDATE sysdiagrams SET [definition] .Write ( 0x0005000000060000000700000008000000090000000A00000006000000610073, null, 0) WHERE diagram_id = @id -- index:44545
    UPDATE sysdiagrams SET [definition] .Write ( 0x0073006500740000000C000000500072006F006A006500630074005000610074, null, 0) WHERE diagram_id = @id -- index:44577
    UPDATE sysdiagrams SET [definition] .Write ( 0x006800000002000B00C67500009E520000C6750000D24C000000000000020000, null, 0) WHERE diagram_id = @id -- index:44609
    UPDATE sysdiagrams SET [definition] .Write ( 0x00F0F0F000000000000000000000000000000000000100000066000000000000, null, 0) WHERE diagram_id = @id -- index:44641
    UPDATE sysdiagrams SET [definition] .Write ( 0x00757600000C4F0000D70C00005801000032000000010000020000D70C000058, null, 0) WHERE diagram_id = @id -- index:44673
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000020000000000FFFFFF0008000080010000001500010000009001444201, null, 0) WHERE diagram_id = @id -- index:44705
    UPDATE sysdiagrams SET [definition] .Write ( 0x00065461686F6D61160046004B005F00500072006F006A006500630074005000, null, 0) WHERE diagram_id = @id -- index:44737
    UPDATE sysdiagrams SET [definition] .Write ( 0x6100740068005F00500072006F006A006500630074002143341208000000AB1A, null, 0) WHERE diagram_id = @id -- index:44769
    UPDATE sysdiagrams SET [definition] .Write ( 0x000089130000785634120700000014010000500072006F006A00650063007400, null, 0) WHERE diagram_id = @id -- index:44801
    UPDATE sysdiagrams SET [definition] .Write ( 0x55006E0075007300650064004900740065006D002000280073006E0061007000, null, 0) WHERE diagram_id = @id -- index:44833
    UPDATE sysdiagrams SET [definition] .Write ( 0x730068006F00740029000000282170A35521502D2821C030282158EAB621B8F6, null, 0) WHERE diagram_id = @id -- index:44865
    UPDATE sysdiagrams SET [definition] .Write ( 0xB62158F5B62148E8B62118EDB621E8E6B62138E6B62148F3B62188F0B62138F1, null, 0) WHERE diagram_id = @id -- index:44897
    UPDATE sysdiagrams SET [definition] .Write ( 0xB62108F6B621C8E2B62128E4B621C8F8B621D8FAB62138FCB62148FEB62128FA, null, 0) WHERE diagram_id = @id -- index:44929
    UPDATE sysdiagrams SET [definition] .Write ( 0xB621F8E8B62100C55B21D0C95B2150C45B2160C65B2180CA5B2120C95B2130CB, null, 0) WHERE diagram_id = @id -- index:44961
    UPDATE sysdiagrams SET [definition] .Write ( 0x5B2110D25B21C0D25B2120D45B21E0E15B21D0D45B21E0D65B2140E35B2150DA, null, 0) WHERE diagram_id = @id -- index:44993
    UPDATE sysdiagrams SET [definition] .Write ( 0x5B2170DE5B2100DB5B21B04C2F21104E2F21C0382F21803B2F2180462F21903D, null, 0) WHERE diagram_id = @id -- index:45025
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000100000005000000540000002C0000002C0000002C00, null, 0) WHERE diagram_id = @id -- index:45057
    UPDATE sysdiagrams SET [definition] .Write ( 0x000034000000000000000000000022290000AB170000000000002D0100000800, null, 0) WHERE diagram_id = @id -- index:45089
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000C000000070000001C0100000609000062070000480300001A040000DF02, null, 0) WHERE diagram_id = @id -- index:45121
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000EC04000027060000B103000027060000CB07000055050000000000000100, null, 0) WHERE diagram_id = @id -- index:45153
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000AB1A00008913000000000000060000000600000002000000020000001C01, null, 0) WHERE diagram_id = @id -- index:45185
    UPDATE sysdiagrams SET [definition] .Write ( 0x00004D0D0000000000000100000039130000C007000000000000020000000200, null, 0) WHERE diagram_id = @id -- index:45217
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002000000020000001C010000060900000100000000000000391300003403, null, 0) WHERE diagram_id = @id -- index:45249
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000002000000020000001C010000060900000000, null, 0) WHERE diagram_id = @id -- index:45281
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000D13100000923000000000000000000000D000000040000000400, null, 0) WHERE diagram_id = @id -- index:45313
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001C01000006090000AA0A0000900600007856341204000000760000000100, null, 0) WHERE diagram_id = @id -- index:45345
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000010000000B00000000000000010000000200000003000000040000000500, null, 0) WHERE diagram_id = @id -- index:45377
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000060000000700000008000000090000000A0000000900000073006E006100, null, 0) WHERE diagram_id = @id -- index:45409
    UPDATE sysdiagrams SET [definition] .Write ( 0x7000730068006F007400000012000000500072006F006A006500630074005500, null, 0) WHERE diagram_id = @id -- index:45441
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0075007300650064004900740065006D00000004000B00097D0000DCC70100, null, 0) WHERE diagram_id = @id -- index:45473
    UPDATE sysdiagrams SET [definition] .Write ( 0x25840000DCC70100258400006CFB0100C48600006CFB01000000000002000000, null, 0) WHERE diagram_id = @id -- index:45505
    UPDATE sysdiagrams SET [definition] .Write ( 0xF0F0F00000000000000000000000000000000000010000006900000000000000, null, 0) WHERE diagram_id = @id -- index:45537
    UPDATE sysdiagrams SET [definition] .Write ( 0xD48400005BDD0100551800005801000032000000010000020000551800005801, null, 0) WHERE diagram_id = @id -- index:45569
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000020000000000FFFFFF000800008001000000150001000000900144420100, null, 0) WHERE diagram_id = @id -- index:45601
    UPDATE sysdiagrams SET [definition] .Write ( 0x065461686F6D61290046004B005F00500072006F006A0065006300740055006E, null, 0) WHERE diagram_id = @id -- index:45633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0075007300650064004900740065006D0073005F00500072006F006A00650063, null, 0) WHERE diagram_id = @id -- index:45665
    UPDATE sysdiagrams SET [definition] .Write ( 0x007400460069006C00650053006E0061007000730068006F0074002143341208, null, 0) WHERE diagram_id = @id -- index:45697
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000088160000DC290000785634120700000014010000530063006800650064, null, 0) WHERE diagram_id = @id -- index:45729
    UPDATE sysdiagrams SET [definition] .Write ( 0x0075006C0065002000280073006E0061007000730068006F0074002900000000, null, 0) WHERE diagram_id = @id -- index:45761
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:45793
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:45825
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:45857
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:45889
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:45921
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:45953
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000100000005000000540000002C0000002C, null, 0) WHERE diagram_id = @id -- index:45985
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000002C0000003400000000000000000000002229000009230000000000002D, null, 0) WHERE diagram_id = @id -- index:46017
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000D0000000C000000070000001C0100000609000062070000480300001A, null, 0) WHERE diagram_id = @id -- index:46049
    UPDATE sysdiagrams SET [definition] .Write ( 0x040000DF020000EC04000027060000B103000027060000CB0700005505000000, null, 0) WHERE diagram_id = @id -- index:46081
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000088160000DC290000000000000F0000000C0000000200000002, null, 0) WHERE diagram_id = @id -- index:46113
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000001C010000F50A0000000000000100000039130000C00700000000000002, null, 0) WHERE diagram_id = @id -- index:46145
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000200000002000000020000001C01000006090000010000000000000039, null, 0) WHERE diagram_id = @id -- index:46177
    UPDATE sysdiagrams SET [definition] .Write ( 0x1300003403000000000000000000000000000002000000020000001C01000006, null, 0) WHERE diagram_id = @id -- index:46209
    UPDATE sysdiagrams SET [definition] .Write ( 0x0900000000000000000000D13100000923000000000000000000000D00000004, null, 0) WHERE diagram_id = @id -- index:46241
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000040000001C01000006090000AA0A000090060000785634120400000064, null, 0) WHERE diagram_id = @id -- index:46273
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000001000000010000000B0000000000000001000000020000000300000004, null, 0) WHERE diagram_id = @id -- index:46305
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000005000000060000000700000008000000090000000A0000000900000073, null, 0) WHERE diagram_id = @id -- index:46337
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E0061007000730068006F0074000000090000005300630068006500640075, null, 0) WHERE diagram_id = @id -- index:46369
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C006500000004000B00097D00001AC60100258400001AC6010025840000AC, null, 0) WHERE diagram_id = @id -- index:46401
    UPDATE sysdiagrams SET [definition] .Write ( 0x9D0100C4860000AC9D01000000000002000000F0F0F000000000000000000000, null, 0) WHERE diagram_id = @id -- index:46433
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000010000006C00000000000000D4840000D2B401003F12000058, null, 0) WHERE diagram_id = @id -- index:46465
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000320000000100000200003F12000058010000020000000000FFFFFF0008, null, 0) WHERE diagram_id = @id -- index:46497
    UPDATE sysdiagrams SET [definition] .Write ( 0x00008001000000150001000000900144420100065461686F6D611F0046004B00, null, 0) WHERE diagram_id = @id -- index:46529
    UPDATE sysdiagrams SET [definition] .Write ( 0x5F005300630068006500640075006C0065005F00500072006F006A0065006300, null, 0) WHERE diagram_id = @id -- index:46561
    UPDATE sysdiagrams SET [definition] .Write ( 0x7400460069006C00650053006E0061007000730068006F007400214334120800, null, 0) WHERE diagram_id = @id -- index:46593
    UPDATE sysdiagrams SET [definition] .Write ( 0x000088160000572C000078563412070000001401000053006300680065006400, null, 0) WHERE diagram_id = @id -- index:46625
    UPDATE sysdiagrams SET [definition] .Write ( 0x75006C0065004600690065006C0064002000280073006E006100700073006800, null, 0) WHERE diagram_id = @id -- index:46657
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00740029000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:46689
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:46721
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:46753
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:46785
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:46817
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:46849
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000000000100000005000000540000002C0000002C00, null, 0) WHERE diagram_id = @id -- index:46881
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002C0000003400000000000000000000002229000009230000000000002D01, null, 0) WHERE diagram_id = @id -- index:46913
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000D0000000C000000070000001C0100000609000062070000480300001A04, null, 0) WHERE diagram_id = @id -- index:46945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000DF020000EC04000027060000B103000027060000CB070000550500000000, null, 0) WHERE diagram_id = @id -- index:46977
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000088160000572C000000000000100000000C000000020000000200, null, 0) WHERE diagram_id = @id -- index:47009
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001C010000F50A0000000000000100000039130000C0070000000000000200, null, 0) WHERE diagram_id = @id -- index:47041
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000200000002000000020000001C0100000609000001000000000000003913, null, 0) WHERE diagram_id = @id -- index:47073
    UPDATE sysdiagrams SET [definition] .Write ( 0x00003403000000000000000000000000000002000000020000001C0100000609, null, 0) WHERE diagram_id = @id -- index:47105
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000D13100000923000000000000000000000D0000000400, null, 0) WHERE diagram_id = @id -- index:47137
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000040000001C01000006090000AA0A00009006000078563412040000006E00, null, 0) WHERE diagram_id = @id -- index:47169
    UPDATE sysdiagrams SET [definition] .Write ( 0x000001000000010000000B000000000000000100000002000000030000000400, null, 0) WHERE diagram_id = @id -- index:47201
    UPDATE sysdiagrams SET [definition] .Write ( 0x000005000000060000000700000008000000090000000A000000090000007300, null, 0) WHERE diagram_id = @id -- index:47233
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0061007000730068006F00740000000E000000530063006800650064007500, null, 0) WHERE diagram_id = @id -- index:47265
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0065004600690065006C006400000002000B00E691000070B20100E6910000, null, 0) WHERE diagram_id = @id -- index:47297
    UPDATE sysdiagrams SET [definition] .Write ( 0x24BC01000000000002000000F0F0F00000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:47329
    UPDATE sysdiagrams SET [definition] .Write ( 0x010000006F00000000000000AC8100009EB601008B0F00005801000032000000, null, 0) WHERE diagram_id = @id -- index:47361
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000200008B0F000058010000020000000000FFFFFF000800008001000000, null, 0) WHERE diagram_id = @id -- index:47393
    UPDATE sysdiagrams SET [definition] .Write ( 0x150001000000900144420100065461686F6D611A0046004B005F005300630068, null, 0) WHERE diagram_id = @id -- index:47425
    UPDATE sysdiagrams SET [definition] .Write ( 0x006500640075006C0065004600690065006C0064005F00530063006800650064, null, 0) WHERE diagram_id = @id -- index:47457
    UPDATE sysdiagrams SET [definition] .Write ( 0x0075006C00650031002143341208000000881600009D09000078563412070000, null, 0) WHERE diagram_id = @id -- index:47489
    UPDATE sysdiagrams SET [definition] .Write ( 0x001401000053006300680065006D006100440061007400610020002800610073, null, 0) WHERE diagram_id = @id -- index:47521
    UPDATE sysdiagrams SET [definition] .Write ( 0x007300650074002900000020005700480045005200450020006E0061006D0065, null, 0) WHERE diagram_id = @id -- index:47553
    UPDATE sysdiagrams SET [definition] .Write ( 0x0020003D00200000009C34902E00210080200045005800490053005400530020, null, 0) WHERE diagram_id = @id -- index:47585
    UPDATE sysdiagrams SET [definition] .Write ( 0x002800530045004C0045004300540020002A002000460052004F004D00200073, null, 0) WHERE diagram_id = @id -- index:47617
    UPDATE sysdiagrams SET [definition] .Write ( 0x00790073006F0062006A00650063007400730020005700480045005200450020, null, 0) WHERE diagram_id = @id -- index:47649
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E0061006D00650020003D00200000008934E52E0022008020004500580049, null, 0) WHERE diagram_id = @id -- index:47681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0053005400530020002800530045004C00450043005400200000000000000000, null, 0) WHERE diagram_id = @id -- index:47713
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000010000, null, 0) WHERE diagram_id = @id -- index:47745
    UPDATE sysdiagrams SET [definition] .Write ( 0x0005000000540000002C0000002C0000002C0000003400000000000000000000, null, 0) WHERE diagram_id = @id -- index:47777
    UPDATE sysdiagrams SET [definition] .Write ( 0x002229000065150000000000002D010000070000000C000000070000001C0100, null, 0) WHERE diagram_id = @id -- index:47809
    UPDATE sysdiagrams SET [definition] .Write ( 0x000609000062070000480300001A040000DF020000EC04000027060000B10300, null, 0) WHERE diagram_id = @id -- index:47841
    UPDATE sysdiagrams SET [definition] .Write ( 0x0027060000CB070000550500000000000001000000881600009D090000000000, null, 0) WHERE diagram_id = @id -- index:47873
    UPDATE sysdiagrams SET [definition] .Write ( 0x00020000000200000002000000020000001C010000F50A000000000000010000, null, 0) WHERE diagram_id = @id -- index:47905
    UPDATE sysdiagrams SET [definition] .Write ( 0x00391300003403000000000000000000000000000002000000020000001C0100, null, 0) WHERE diagram_id = @id -- index:47937
    UPDATE sysdiagrams SET [definition] .Write ( 0x0006090000010000000000000039130000340300000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:47969
    UPDATE sysdiagrams SET [definition] .Write ( 0x0002000000020000001C010000060900000000000000000000D1310000092300, null, 0) WHERE diagram_id = @id -- index:48001
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000D00000004000000040000001C01000006090000AA0A00, null, 0) WHERE diagram_id = @id -- index:48033
    UPDATE sysdiagrams SET [definition] .Write ( 0x009006000078563412040000006200000001000000010000000B000000000000, null, 0) WHERE diagram_id = @id -- index:48065
    UPDATE sysdiagrams SET [definition] .Write ( 0x0001000000020000000300000004000000050000000600000007000000080000, null, 0) WHERE diagram_id = @id -- index:48097
    UPDATE sysdiagrams SET [definition] .Write ( 0x00090000000A000000060000006100730073006500740000000B000000530063, null, 0) WHERE diagram_id = @id -- index:48129
    UPDATE sysdiagrams SET [definition] .Write ( 0x00680065006D006100440061007400610000002143341208000000881600006B, null, 0) WHERE diagram_id = @id -- index:48161
    UPDATE sysdiagrams SET [definition] .Write ( 0x2200007856341207000000140100005700610072006E0069006E006700200028, null, 0) WHERE diagram_id = @id -- index:48193
    UPDATE sysdiagrams SET [definition] .Write ( 0x0073006E0061007000730068006F007400290000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:48225
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:48257
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:48289
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:48321
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:48353
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:48385
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:48417
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000100000005000000540000002C0000002C0000002C00000034, null, 0) WHERE diagram_id = @id -- index:48449
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000002229000009230000000000002D0100000D0000000C, null, 0) WHERE diagram_id = @id -- index:48481
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000070000001C0100000609000062070000480300001A040000DF020000EC, null, 0) WHERE diagram_id = @id -- index:48513
    UPDATE sysdiagrams SET [definition] .Write ( 0x04000027060000B103000027060000CB07000055050000000000000100000088, null, 0) WHERE diagram_id = @id -- index:48545
    UPDATE sysdiagrams SET [definition] .Write ( 0x1600006B220000000000000C0000000C00000002000000020000001C010000F5, null, 0) WHERE diagram_id = @id -- index:48577
    UPDATE sysdiagrams SET [definition] .Write ( 0x0A0000000000000100000039130000930E000000000000050000000500000002, null, 0) WHERE diagram_id = @id -- index:48609
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000020000001C010000060900000100000000000000391300003403000000, null, 0) WHERE diagram_id = @id -- index:48641
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000002000000020000001C010000060900000000000000, null, 0) WHERE diagram_id = @id -- index:48673
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000D13100000923000000000000000000000D00000004000000040000001C, null, 0) WHERE diagram_id = @id -- index:48705
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000006090000AA0A0000900600007856341204000000620000000100000001, null, 0) WHERE diagram_id = @id -- index:48737
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000B00000000000000010000000200000003000000040000000500000006, null, 0) WHERE diagram_id = @id -- index:48769
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000700000008000000090000000A0000000900000073006E006100700073, null, 0) WHERE diagram_id = @id -- index:48801
    UPDATE sysdiagrams SET [definition] .Write ( 0x0068006F0074000000080000005700610072006E0069006E006700000004000B, null, 0) WHERE diagram_id = @id -- index:48833
    UPDATE sysdiagrams SET [definition] .Write ( 0x00266E000080700000427500008070000042750000AA82000088770000AA8200, null, 0) WHERE diagram_id = @id -- index:48865
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000002000000F0F0F00001000000000000000000000000000000010000, null, 0) WHERE diagram_id = @id -- index:48897
    UPDATE sysdiagrams SET [definition] .Write ( 0x007300000000000000F175000023750000381000005801000032000000010000, null, 0) WHERE diagram_id = @id -- index:48929
    UPDATE sysdiagrams SET [definition] .Write ( 0x0200003810000058010000020000000000FFFFFF000800008001000000150001, null, 0) WHERE diagram_id = @id -- index:48961
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000900144420100065461686F6D611A0046004B005F005700610072006E00, null, 0) WHERE diagram_id = @id -- index:48993
    UPDATE sysdiagrams SET [definition] .Write ( 0x69006E0067005F0045006C0065006D0065006E00740049006E00730074006100, null, 0) WHERE diagram_id = @id -- index:49025
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E006300650004000B00266E0000427200008E740000427200008E7400006C84, null, 0) WHERE diagram_id = @id -- index:49057
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000887700006C8400000000000002000000F0F0F00001000000000000000000, null, 0) WHERE diagram_id = @id -- index:49089
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000100000075000000000000003D75000099770000E61000005801, null, 0) WHERE diagram_id = @id -- index:49121
    UPDATE sysdiagrams SET [definition] .Write ( 0x000032000000010000020000E610000058010000020000000000FFFFFF000800, null, 0) WHERE diagram_id = @id -- index:49153
    UPDATE sysdiagrams SET [definition] .Write ( 0x008001000000150001000000900144420100065461686F6D611B0046004B005F, null, 0) WHERE diagram_id = @id -- index:49185
    UPDATE sysdiagrams SET [definition] .Write ( 0x005700610072006E0069006E0067005F0045006C0065006D0065006E00740049, null, 0) WHERE diagram_id = @id -- index:49217
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E007300740061006E0063006500310004000B00546F00000E4B0100546F00, null, 0) WHERE diagram_id = @id -- index:49249
    UPDATE sysdiagrams SET [definition] .Write ( 0x00F3430100AA820000F3430100AA820000439500000000000002000000F0F0F0, null, 0) WHERE diagram_id = @id -- index:49281
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000010000007700000000000000598300, null, 0) WHERE diagram_id = @id -- index:49313
    UPDATE sysdiagrams SET [definition] .Write ( 0x003AFA0000E91100005801000032000000010000020000E91100005801000002, null, 0) WHERE diagram_id = @id -- index:49345
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000FFFFFF000800008001000000150001000000900144420100065461, null, 0) WHERE diagram_id = @id -- index:49377
    UPDATE sysdiagrams SET [definition] .Write ( 0x686F6D611E0046004B005F005700610072006E0069006E0067005F0050007200, null, 0) WHERE diagram_id = @id -- index:49409
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F006A00650063007400460069006C00650053006E0061007000730068006F00, null, 0) WHERE diagram_id = @id -- index:49441
    UPDATE sysdiagrams SET [definition] .Write ( 0x7400214334120800000088160000751D00007856341207000000140100005700, null, 0) WHERE diagram_id = @id -- index:49473
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F0072006B007300650074002000280073006E0061007000730068006F007400, null, 0) WHERE diagram_id = @id -- index:49505
    UPDATE sysdiagrams SET [definition] .Write ( 0x2900000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:49537
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:49569
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:49601
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:49633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:49665
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:49697
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000001000000050000005400, null, 0) WHERE diagram_id = @id -- index:49729
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002C0000002C0000002C00000034000000000000000000000022290000C320, null, 0) WHERE diagram_id = @id -- index:49761
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000002D0100000C0000000C000000070000001C010000060900006207, null, 0) WHERE diagram_id = @id -- index:49793
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000480300001A040000DF020000EC04000027060000B103000027060000CB07, null, 0) WHERE diagram_id = @id -- index:49825
    UPDATE sysdiagrams SET [definition] .Write ( 0x000055050000000000000100000088160000751D0000000000000A0000000A00, null, 0) WHERE diagram_id = @id -- index:49857
    UPDATE sysdiagrams SET [definition] .Write ( 0x000002000000020000001C010000F50A0000000000000100000039130000C007, null, 0) WHERE diagram_id = @id -- index:49889
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000020000000200000002000000020000001C010000060900000100, null, 0) WHERE diagram_id = @id -- index:49921
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000003913000034030000000000000000000000000000020000000200, null, 0) WHERE diagram_id = @id -- index:49953
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001C010000060900000000000000000000D131000009230000000000000000, null, 0) WHERE diagram_id = @id -- index:49985
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000D00000004000000040000001C01000006090000AA0A0000900600007856, null, 0) WHERE diagram_id = @id -- index:50017
    UPDATE sysdiagrams SET [definition] .Write ( 0x3412040000006200000001000000010000000B00000000000000010000000200, null, 0) WHERE diagram_id = @id -- index:50049
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000030000000400000005000000060000000700000008000000090000000A00, null, 0) WHERE diagram_id = @id -- index:50081
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000900000073006E0061007000730068006F00740000000800000057006F00, null, 0) WHERE diagram_id = @id -- index:50113
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006B00730065007400000004000B00C2970000685B0000F28F0000685B0000, null, 0) WHERE diagram_id = @id -- index:50145
    UPDATE sysdiagrams SET [definition] .Write ( 0xF28F0000D6830000108E0000D68300000000000002000000F0F0F00001000000, null, 0) WHERE diagram_id = @id -- index:50177
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000010000007A000000000000008C8300009E6A0000, null, 0) WHERE diagram_id = @id -- index:50209
    UPDATE sysdiagrams SET [definition] .Write ( 0xB70B00005801000032000000010000020000B70B000058010000020000000000, null, 0) WHERE diagram_id = @id -- index:50241
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFF000800008001000000150001000000900144420100065461686F6D6112, null, 0) WHERE diagram_id = @id -- index:50273
    UPDATE sysdiagrams SET [definition] .Write ( 0x0046004B005F005700610072006E0069006E0067005F0057006F0072006B0073, null, 0) WHERE diagram_id = @id -- index:50305
    UPDATE sysdiagrams SET [definition] .Write ( 0x006500740004000B00167100000E4B010016710000A7440100E4A20000A74401, null, 0) WHERE diagram_id = @id -- index:50337
    UPDATE sysdiagrams SET [definition] .Write ( 0x00E4A20000A16900000000000002000000F0F0F0000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:50369
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000010000007C0000000000000093A30000AFF30000E9110000580100, null, 0) WHERE diagram_id = @id -- index:50401
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032000000010000020000E911000058010000020000000000FFFFFF00080000, null, 0) WHERE diagram_id = @id -- index:50433
    UPDATE sysdiagrams SET [definition] .Write ( 0x8001000000150001000000900144420100065461686F6D611E0046004B005F00, null, 0) WHERE diagram_id = @id -- index:50465
    UPDATE sysdiagrams SET [definition] .Write ( 0x57006F0072006B007300650074005F00500072006F006A006500630074004600, null, 0) WHERE diagram_id = @id -- index:50497
    UPDATE sysdiagrams SET [definition] .Write ( 0x69006C00650053006E0061007000730068006F00740004000B00C2970000A659, null, 0) WHERE diagram_id = @id -- index:50529
    UPDATE sysdiagrams SET [definition] .Write ( 0x000042750000A659000042750000BE6E0000266E0000BE6E0000000000000200, null, 0) WHERE diagram_id = @id -- index:50561
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000F0F0F00001000000000000000000000000000000010000007E0000000000, null, 0) WHERE diagram_id = @id -- index:50593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000906700009F57000038100000580100003200000001000002000038100000, null, 0) WHERE diagram_id = @id -- index:50625
    UPDATE sysdiagrams SET [definition] .Write ( 0x58010000020000000000FFFFFF00080000800100000015000100000090014442, null, 0) WHERE diagram_id = @id -- index:50657
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100065461686F6D611A0046004B005F0045006C0065006D0065006E00740049, null, 0) WHERE diagram_id = @id -- index:50689
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E007300740061006E00630065005F0057006F0072006B0073006500740000, null, 0) WHERE diagram_id = @id -- index:50721
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:50753
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:50785
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:50817
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:50849
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:50881
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:50913
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:50945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:50977
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51009
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51041
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51073
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51105
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51137
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51169
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000000FEFFFFFFFEFFFFFF0400000005000000060000000700000008000000, null, 0) WHERE diagram_id = @id -- index:51201
    UPDATE sysdiagrams SET [definition] .Write ( 0x090000000A0000000B0000000C0000000D0000000E0000000F00000010000000, null, 0) WHERE diagram_id = @id -- index:51233
    UPDATE sysdiagrams SET [definition] .Write ( 0x1100000012000000130000001400000015000000160000001700000018000000, null, 0) WHERE diagram_id = @id -- index:51265
    UPDATE sysdiagrams SET [definition] .Write ( 0x190000001A0000001B0000001C0000001D0000001E0000001F00000020000000, null, 0) WHERE diagram_id = @id -- index:51297
    UPDATE sysdiagrams SET [definition] .Write ( 0x2100000022000000230000002400000025000000260000002700000028000000, null, 0) WHERE diagram_id = @id -- index:51329
    UPDATE sysdiagrams SET [definition] .Write ( 0x290000002A0000002B0000002C0000002D0000002E0000002F00000030000000, null, 0) WHERE diagram_id = @id -- index:51361
    UPDATE sysdiagrams SET [definition] .Write ( 0xFEFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51393
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51425
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51457
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51489
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51521
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51553
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51585
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51617
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51649
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:51681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100FEFF030A0000FFFFFFFF0000000000000000000000000000000017000000, null, 0) WHERE diagram_id = @id -- index:51713
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D6963726F736F66742044445320466F726D20322E300010000000456D626564, null, 0) WHERE diagram_id = @id -- index:51745
    UPDATE sysdiagrams SET [definition] .Write ( 0x646564204F626A6563740000000000F439B27100000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51777
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51809
    UPDATE sysdiagrams SET [definition] .Write ( 0x010003000000000000000C0000000B0000004E61BC0000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51841
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:51873
    UPDATE sysdiagrams SET [definition] .Write ( 0xDBE6B0E91C81D011AD5100A0C90F573900000200A017CD260389D50102020000, null, 0) WHERE diagram_id = @id -- index:51905
    UPDATE sysdiagrams SET [definition] .Write ( 0x1048450000000000000000000000000000000000D00100004400610074006100, null, 0) WHERE diagram_id = @id -- index:51937
    UPDATE sysdiagrams SET [definition] .Write ( 0x200053006F0075007200630065003D004300540043004C0054004D004E004400, null, 0) WHERE diagram_id = @id -- index:51969
    UPDATE sysdiagrams SET [definition] .Write ( 0x4100560045004C0032003B0049006E0069007400690061006C00200043006100, null, 0) WHERE diagram_id = @id -- index:52001
    UPDATE sysdiagrams SET [definition] .Write ( 0x740061006C006F0067003D00430054004300420049004D004400610074006100, null, 0) WHERE diagram_id = @id -- index:52033
    UPDATE sysdiagrams SET [definition] .Write ( 0x3B0049006E007400650067007200610074006500640020005300650063007500, null, 0) WHERE diagram_id = @id -- index:52065
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006900740079003D0054007200750065003B004D0075006C00740069007000, null, 0) WHERE diagram_id = @id -- index:52097
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650041006300740069007600650052006500730075006C00740053006500, null, 0) WHERE diagram_id = @id -- index:52129
    UPDATE sysdiagrams SET [definition] .Write ( 0x740073003D00460061006C00730065003B0043006F006E006E00650063007400, null, 0) WHERE diagram_id = @id -- index:52161
    UPDATE sysdiagrams SET [definition] .Write ( 0x2000540069006D0065006F00750074003D00330030003B005400720075007300, null, 0) WHERE diagram_id = @id -- index:52193
    UPDATE sysdiagrams SET [definition] .Write ( 0x0300440064007300530074007200650061006D00000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:52225
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:52257
    UPDATE sysdiagrams SET [definition] .Write ( 0x160002000300000006000000FFFFFFFF00000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:52289
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000670000009971000000000000, null, 0) WHERE diagram_id = @id -- index:52321
    UPDATE sysdiagrams SET [definition] .Write ( 0x53006300680065006D0061002000550044005600200044006500660061007500, null, 0) WHERE diagram_id = @id -- index:52353
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00740000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:52385
    UPDATE sysdiagrams SET [definition] .Write ( 0x26000200FFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:52417
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000020000001600000000000000, null, 0) WHERE diagram_id = @id -- index:52449
    UPDATE sysdiagrams SET [definition] .Write ( 0x440053005200450046002D0053004300480045004D0041002D0043004F004E00, null, 0) WHERE diagram_id = @id -- index:52481
    UPDATE sysdiagrams SET [definition] .Write ( 0x540045004E005400530000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:52513
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0002010500000007000000FFFFFFFF00000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:52545
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000000000000000003000000480B000000000000, null, 0) WHERE diagram_id = @id -- index:52577
    UPDATE sysdiagrams SET [definition] .Write ( 0x53006300680065006D0061002000550044005600200044006500660061007500, null, 0) WHERE diagram_id = @id -- index:52609
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C007400200050006F0073007400200056003600000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:52641
    UPDATE sysdiagrams SET [definition] .Write ( 0x36000200FFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:52673
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000310000001200000000000000, null, 0) WHERE diagram_id = @id -- index:52705
    UPDATE sysdiagrams SET [definition] .Write ( 0x8100000082000000830000008400000085000000860000008700000088000000, null, 0) WHERE diagram_id = @id -- index:52737
    UPDATE sysdiagrams SET [definition] .Write ( 0x890000008A0000008B0000008C0000008D0000008E0000008F00000090000000, null, 0) WHERE diagram_id = @id -- index:52769
    UPDATE sysdiagrams SET [definition] .Write ( 0x9100000092000000930000009400000095000000960000009700000098000000, null, 0) WHERE diagram_id = @id -- index:52801
    UPDATE sysdiagrams SET [definition] .Write ( 0x990000009A0000009B0000009C0000009D0000009E0000009F000000FEFFFFFF, null, 0) WHERE diagram_id = @id -- index:52833
    UPDATE sysdiagrams SET [definition] .Write ( 0xA1000000A2000000A3000000A4000000A5000000FEFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:52865
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:52897
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:52929
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:52961
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:52993
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:53025
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:53057
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:53089
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:53121
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:53153
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:53185
    UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @id -- index:53217
    UPDATE sysdiagrams SET [definition] .Write ( 0x0C00000000000000B33202000100260000007300630068005F006C0061006200, null, 0) WHERE diagram_id = @id -- index:53249
    UPDATE sysdiagrams SET [definition] .Write ( 0x65006C0073005F00760069007300690062006C0065000000010000000B000000, null, 0) WHERE diagram_id = @id -- index:53281
    UPDATE sysdiagrams SET [definition] .Write ( 0x1E00000000000000000000000000000000000000640000000000000000000000, null, 0) WHERE diagram_id = @id -- index:53313
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000010000000100000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:53345
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000D002000006002800000041006300740069007600650054006100, null, 0) WHERE diagram_id = @id -- index:53377
    UPDATE sysdiagrams SET [definition] .Write ( 0x62006C00650056006900650077004D006F006400650000000100000008000400, null, 0) WHERE diagram_id = @id -- index:53409
    UPDATE sysdiagrams SET [definition] .Write ( 0x000031000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:53441
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00300000000100000008003A00000034002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:53473
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030002C0031002C0031003800390030002C00, null, 0) WHERE diagram_id = @id -- index:53505
    UPDATE sysdiagrams SET [definition] .Write ( 0x35002C0031003200360030000000200000005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:53537
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065003A00310000000100000008001E00000032002C00, null, 0) WHERE diagram_id = @id -- index:53569
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C003200380034002C0030002C0032003800300035000000200000005400, null, 0) WHERE diagram_id = @id -- index:53601
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00320000000100, null, 0) WHERE diagram_id = @id -- index:53633
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008001E00000032002C0030002C003200380034002C0030002C0032003300, null, 0) WHERE diagram_id = @id -- index:53665
    UPDATE sysdiagrams SET [definition] .Write ( 0x310030000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:53697
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00330000000100000008001E00000032002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:53729
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:53761
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00340000000100000008003E000000, null, 0) WHERE diagram_id = @id -- index:53793
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C003200380034002C0030002C0032003300310030002C003100, null, 0) WHERE diagram_id = @id -- index:53825
    UPDATE sysdiagrams SET [definition] .Write ( 0x32002C0032003700330030002C00310031002C00310036003800300000000200, null, 0) WHERE diagram_id = @id -- index:53857
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000200000000000000000000000000000000000000D0020000060028000000, null, 0) WHERE diagram_id = @id -- index:53889
    UPDATE sysdiagrams SET [definition] .Write ( 0x4100630074006900760065005400610062006C00650056006900650077004D00, null, 0) WHERE diagram_id = @id -- index:53921
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00640065000000010000000800040000003100000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:53953
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0030000000010000000800, null, 0) WHERE diagram_id = @id -- index:53985
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00000034002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:54017
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0031002C0031003800390030002C0035002C00310032003600300000002000, null, 0) WHERE diagram_id = @id -- index:54049
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005400610062006C00650056006900650077004D006F00640065003A003100, null, 0) WHERE diagram_id = @id -- index:54081
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000008001E00000032002C0030002C003200380034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:54113
    UPDATE sysdiagrams SET [definition] .Write ( 0x33003300310035000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:54145
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00320000000100000008001E00000032002C0030002C00, null, 0) WHERE diagram_id = @id -- index:54177
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C003200330031003000000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:54209
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0033000000010000000800, null, 0) WHERE diagram_id = @id -- index:54241
    UPDATE sysdiagrams SET [definition] .Write ( 0x1E00000032002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:54273
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000200000005400610062006C00650056006900650077004D006F0064006500, null, 0) WHERE diagram_id = @id -- index:54305
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00340000000100000008003E00000034002C0030002C003200380034002C00, null, 0) WHERE diagram_id = @id -- index:54337
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0032003300310030002C00310032002C0032003700330030002C003100, null, 0) WHERE diagram_id = @id -- index:54369
    UPDATE sysdiagrams SET [definition] .Write ( 0x31002C00310036003800300000000300000003000000000000005C0000000100, null, 0) WHERE diagram_id = @id -- index:54401
    UPDATE sysdiagrams SET [definition] .Write ( 0x40400100000073006E0061007000730068006F007400000046004B005F004400, null, 0) WHERE diagram_id = @id -- index:54433
    UPDATE sysdiagrams SET [definition] .Write ( 0x690073006300690070006C0069006E0065005F0045006C0065006D0065006E00, null, 0) WHERE diagram_id = @id -- index:54465
    UPDATE sysdiagrams SET [definition] .Write ( 0x740044006500660069006E006900740069006F006E0031000000000000000000, null, 0) WHERE diagram_id = @id -- index:54497
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000C4020000000004000000040000000300000008000000015B6C21B05B6C21, null, 0) WHERE diagram_id = @id -- index:54529
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000AD0F00000100000500000005000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:54561
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000D0020000060028000000410063007400690076006500540061, null, 0) WHERE diagram_id = @id -- index:54593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0062006C00650056006900650077004D006F0064006500000001000000080004, null, 0) WHERE diagram_id = @id -- index:54625
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000031000000200000005400610062006C00650056006900650077004D006F, null, 0) WHERE diagram_id = @id -- index:54657
    UPDATE sysdiagrams SET [definition] .Write ( 0x00640065003A00300000000100000008003A00000034002C0030002C00320038, null, 0) WHERE diagram_id = @id -- index:54689
    UPDATE sysdiagrams SET [definition] .Write ( 0x0034002C0030002C0032003300310030002C0031002C0031003800390030002C, null, 0) WHERE diagram_id = @id -- index:54721
    UPDATE sysdiagrams SET [definition] .Write ( 0x0035002C0031003200360030000000200000005400610062006C006500560069, null, 0) WHERE diagram_id = @id -- index:54753
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650077004D006F00640065003A00310000000100000008001E00000032002C, null, 0) WHERE diagram_id = @id -- index:54785
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C003200380034002C0030002C00330031003000350000002000000054, null, 0) WHERE diagram_id = @id -- index:54817
    UPDATE sysdiagrams SET [definition] .Write ( 0x00610062006C00650056006900650077004D006F00640065003A003200000001, null, 0) WHERE diagram_id = @id -- index:54849
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000008001E00000032002C0030002C003200380034002C0030002C00320033, null, 0) WHERE diagram_id = @id -- index:54881
    UPDATE sysdiagrams SET [definition] .Write ( 0x00310030000000200000005400610062006C00650056006900650077004D006F, null, 0) WHERE diagram_id = @id -- index:54913
    UPDATE sysdiagrams SET [definition] .Write ( 0x00640065003A00330000000100000008001E00000032002C0030002C00320038, null, 0) WHERE diagram_id = @id -- index:54945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0034002C0030002C0032003300310030000000200000005400610062006C0065, null, 0) WHERE diagram_id = @id -- index:54977
    UPDATE sysdiagrams SET [definition] .Write ( 0x0056006900650077004D006F00640065003A00340000000100000008003E0000, null, 0) WHERE diagram_id = @id -- index:55009
    UPDATE sysdiagrams SET [definition] .Write ( 0x0034002C0030002C003200380034002C0030002C0032003300310030002C0031, null, 0) WHERE diagram_id = @id -- index:55041
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032002C0032003700330030002C00310031002C003100360038003000000006, null, 0) WHERE diagram_id = @id -- index:55073
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000060000000000000064000000010000000100000073006E006100700073, null, 0) WHERE diagram_id = @id -- index:55105
    UPDATE sysdiagrams SET [definition] .Write ( 0x0068006F007400000046004B005F0045006C0065006D0065006E00740049006E, null, 0) WHERE diagram_id = @id -- index:55137
    UPDATE sysdiagrams SET [definition] .Write ( 0x007300740061006E00630065005F0045006C0065006D0065006E007400440065, null, 0) WHERE diagram_id = @id -- index:55169
    UPDATE sysdiagrams SET [definition] .Write ( 0x00660069006E006900740069006F006E0000000000000000000000C402000000, null, 0) WHERE diagram_id = @id -- index:55201
    UPDATE sysdiagrams SET [definition] .Write ( 0x0007000000070000000600000008000000016B6C21706B6C2100000000000000, null, 0) WHERE diagram_id = @id -- index:55233
    UPDATE sysdiagrams SET [definition] .Write ( 0x00AD0F0000010000080000000800000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:55265
    UPDATE sysdiagrams SET [definition] .Write ( 0xD00200000600280000004100630074006900760065005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:55297
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F006400650000000100000008000400000031000000, null, 0) WHERE diagram_id = @id -- index:55329
    UPDATE sysdiagrams SET [definition] .Write ( 0x200000005400610062006C00650056006900650077004D006F00640065003A00, null, 0) WHERE diagram_id = @id -- index:55361
    UPDATE sysdiagrams SET [definition] .Write ( 0x300000000100000008003A00000034002C0030002C003200380034002C003000, null, 0) WHERE diagram_id = @id -- index:55393
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0032003300310030002C0031002C0031003800390030002C0035002C003100, null, 0) WHERE diagram_id = @id -- index:55425
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200360030000000200000005400610062006C00650056006900650077004D00, null, 0) WHERE diagram_id = @id -- index:55457
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00640065003A00310000000100000008001E00000032002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:55489
    UPDATE sysdiagrams SET [definition] .Write ( 0x380034002C0030002C0035003300370030000000200000005400610062006C00, null, 0) WHERE diagram_id = @id -- index:55521
    UPDATE sysdiagrams SET [definition] .Write ( 0x650056006900650077004D006F00640065003A00320000000100000008001E00, null, 0) WHERE diagram_id = @id -- index:55553
    UPDATE sysdiagrams SET [definition] .Write ( 0x000032002C0030002C003200380034002C0030002C0032003300310030000000, null, 0) WHERE diagram_id = @id -- index:55585
    UPDATE sysdiagrams SET [definition] .Write ( 0x200000005400610062006C00650056006900650077004D006F00640065003A00, null, 0) WHERE diagram_id = @id -- index:55617
    UPDATE sysdiagrams SET [definition] .Write ( 0x330000000100000008001E00000032002C0030002C003200380034002C003000, null, 0) WHERE diagram_id = @id -- index:55649
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0032003300310030000000200000005400610062006C006500560069006500, null, 0) WHERE diagram_id = @id -- index:55681
    UPDATE sysdiagrams SET [definition] .Write ( 0x77004D006F00640065003A00340000000100000008003E00000034002C003000, null, 0) WHERE diagram_id = @id -- index:55713
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C003200380034002C0030002C0032003300310030002C00310032002C003200, null, 0) WHERE diagram_id = @id -- index:55745
    UPDATE sysdiagrams SET [definition] .Write ( 0x3700330030002C00310031002C00310036003800300000000900000009000000, null, 0) WHERE diagram_id = @id -- index:55777
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000008000000001C578210100000073006E0061007000730068006F007400, null, 0) WHERE diagram_id = @id -- index:55809
    UPDATE sysdiagrams SET [definition] .Write ( 0x000046004B005F0045006C0065006D0065006E00740049006E00730074006100, null, 0) WHERE diagram_id = @id -- index:55841
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0063006500440069006D0065006E00730069006F006E005300650067006D00, null, 0) WHERE diagram_id = @id -- index:55873
    UPDATE sysdiagrams SET [definition] .Write ( 0x65006E0074005F0045006C0065006D0065006E00740049006E00730074006100, null, 0) WHERE diagram_id = @id -- index:55905
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E006300650000000000000000000000C402000000000A0000000A0000000900, null, 0) WHERE diagram_id = @id -- index:55937
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000800000001696C21F0696C210000000000000000AD0F00000100000B0000, null, 0) WHERE diagram_id = @id -- index:55969
    UPDATE sysdiagrams SET [definition] .Write ( 0x000B00000000000000000000000000000000000000D002000006002800000041, null, 0) WHERE diagram_id = @id -- index:56001
    UPDATE sysdiagrams SET [definition] .Write ( 0x00630074006900760065005400610062006C00650056006900650077004D006F, null, 0) WHERE diagram_id = @id -- index:56033
    UPDATE sysdiagrams SET [definition] .Write ( 0x006400650000000100000008000400000031000000200000005400610062006C, null, 0) WHERE diagram_id = @id -- index:56065
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650056006900650077004D006F00640065003A00300000000100000008003A, null, 0) WHERE diagram_id = @id -- index:56097
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000034002C0030002C003200380034002C0030002C0032003300310030002C, null, 0) WHERE diagram_id = @id -- index:56129
    UPDATE sysdiagrams SET [definition] .Write ( 0x0031002C0031003800390030002C0035002C0031003200360030000000200000, null, 0) WHERE diagram_id = @id -- index:56161
    UPDATE sysdiagrams SET [definition] .Write ( 0x005400610062006C00650056006900650077004D006F00640065003A00310000, null, 0) WHERE diagram_id = @id -- index:56193
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100000008001E00000032002C0030002C003200380034002C0030002C0033, null, 0) WHERE diagram_id = @id -- index:56225
    UPDATE sysdiagrams SET [definition] .Write ( 0x003900390030000000200000005400610062006C00650056006900650077004D, null, 0) WHERE diagram_id = @id -- index:56257
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00640065003A00320000000100000008001E00000032002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:56289
    UPDATE sysdiagrams SET [definition] .Write ( 0x00380034002C0030002C0032003300310030000000200000005400610062006C, null, 0) WHERE diagram_id = @id -- index:56321
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650056006900650077004D006F00640065003A00330000000100000008001E, null, 0) WHERE diagram_id = @id -- index:56353
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000032002C0030002C003200380034002C0030002C00320033003100300000, null, 0) WHERE diagram_id = @id -- index:56385
    UPDATE sysdiagrams SET [definition] .Write ( 0x00200000005400610062006C00650056006900650077004D006F00640065003A, null, 0) WHERE diagram_id = @id -- index:56417
    UPDATE sysdiagrams SET [definition] .Write ( 0x00340000000100000008003E00000034002C0030002C003200380034002C0030, null, 0) WHERE diagram_id = @id -- index:56449
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0032003300310030002C00310032002C0032003700330030002C00310031, null, 0) WHERE diagram_id = @id -- index:56481
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C00310036003800300000000C0000000C0000000000000070000000010300, null, 0) WHERE diagram_id = @id -- index:56513
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100000073006E0061007000730068006F007400000046004B005F0045006C, null, 0) WHERE diagram_id = @id -- index:56545
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065006D0065006E00740050006100720061006D006500740065007200560061, null, 0) WHERE diagram_id = @id -- index:56577
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C00750065005F0045006C0065006D0065006E00740044006500660069006E, null, 0) WHERE diagram_id = @id -- index:56609
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900740069006F006E0000000000000000000000C402000000000D0000000D, null, 0) WHERE diagram_id = @id -- index:56641
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000C00000008000000016A6C21706A6C210000000000000000AD0F000001, null, 0) WHERE diagram_id = @id -- index:56673
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000E0000000E000000000000006C000000010400000100000073006E006100, null, 0) WHERE diagram_id = @id -- index:56705
    UPDATE sysdiagrams SET [definition] .Write ( 0x7000730068006F007400000046004B005F0045006C0065006D0065006E007400, null, 0) WHERE diagram_id = @id -- index:56737
    UPDATE sysdiagrams SET [definition] .Write ( 0x50006100720061006D006500740065007200560061006C00750065005F004500, null, 0) WHERE diagram_id = @id -- index:56769
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0065006D0065006E00740049006E007300740061006E006300650000000000, null, 0) WHERE diagram_id = @id -- index:56801
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000C402000000000F0000000F0000000E0000000800000001656C21, null, 0) WHERE diagram_id = @id -- index:56833
    UPDATE sysdiagrams SET [definition] .Write ( 0xF0656C210000000000000000AD0F000001000010000000100000000000000000, null, 0) WHERE diagram_id = @id -- index:56865
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000D00200000600280000004100630074006900760065, null, 0) WHERE diagram_id = @id -- index:56897
    UPDATE sysdiagrams SET [definition] .Write ( 0x005400610062006C00650056006900650077004D006F00640065000000010000, null, 0) WHERE diagram_id = @id -- index:56929
    UPDATE sysdiagrams SET [definition] .Write ( 0x0008000400000031000000200000005400610062006C00650056006900650077, null, 0) WHERE diagram_id = @id -- index:56961
    UPDATE sysdiagrams SET [definition] .Write ( 0x004D006F00640065003A00300000000100000008003A00000034002C0030002C, null, 0) WHERE diagram_id = @id -- index:56993
    UPDATE sysdiagrams SET [definition] .Write ( 0x003200380034002C0030002C0032003300310030002C0031002C003100380039, null, 0) WHERE diagram_id = @id -- index:57025
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C0035002C0031003200360030000000200000005400610062006C0065, null, 0) WHERE diagram_id = @id -- index:57057
    UPDATE sysdiagrams SET [definition] .Write ( 0x0056006900650077004D006F00640065003A00310000000100000008001E0000, null, 0) WHERE diagram_id = @id -- index:57089
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032002C0030002C003200380034002C0030002C003200380030003500000020, null, 0) WHERE diagram_id = @id -- index:57121
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000005400610062006C00650056006900650077004D006F00640065003A0032, null, 0) WHERE diagram_id = @id -- index:57153
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000008001E00000032002C0030002C003200380034002C0030002C, null, 0) WHERE diagram_id = @id -- index:57185
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032003300310030000000200000005400610062006C00650056006900650077, null, 0) WHERE diagram_id = @id -- index:57217
    UPDATE sysdiagrams SET [definition] .Write ( 0x004D006F00640065003A00330000000100000008001E00000032002C0030002C, null, 0) WHERE diagram_id = @id -- index:57249
    UPDATE sysdiagrams SET [definition] .Write ( 0x003200380034002C0030002C0032003300310030000000200000005400610062, null, 0) WHERE diagram_id = @id -- index:57281
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C00650056006900650077004D006F00640065003A00340000000100000008, null, 0) WHERE diagram_id = @id -- index:57313
    UPDATE sysdiagrams SET [definition] .Write ( 0x003E00000034002C0030002C003200380034002C0030002C0032003300310030, null, 0) WHERE diagram_id = @id -- index:57345
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C00310032002C0032003700330030002C00310031002C0031003600380030, null, 0) WHERE diagram_id = @id -- index:57377
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000001100000011000000000000005E000000013FBC580100000073006E0061, null, 0) WHERE diagram_id = @id -- index:57409
    UPDATE sysdiagrams SET [definition] .Write ( 0x007000730068006F007400000046004B005F0045006C0065006D0065006E0074, null, 0) WHERE diagram_id = @id -- index:57441
    UPDATE sysdiagrams SET [definition] .Write ( 0x0054007900700065005F0045006C0065006D0065006E00740044006500660069, null, 0) WHERE diagram_id = @id -- index:57473
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E006900740069006F006E00310000000000000000000000C4020000000012, null, 0) WHERE diagram_id = @id -- index:57505
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000012000000110000000800000001676C2170676C210000000000000000AD, null, 0) WHERE diagram_id = @id -- index:57537
    UPDATE sysdiagrams SET [definition] .Write ( 0x0F00000100001300000013000000000000006400000001000000010000007300, null, 0) WHERE diagram_id = @id -- index:57569
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0061007000730068006F007400000046004B005F0045006C0065006D006500, null, 0) WHERE diagram_id = @id -- index:57601
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E00740050006100720061006D006500740065007200560061006C0075006500, null, 0) WHERE diagram_id = @id -- index:57633
    UPDATE sysdiagrams SET [definition] .Write ( 0x5F0045006C0065006D0065006E00740054007900700065000000000000000000, null, 0) WHERE diagram_id = @id -- index:57665
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000C402000000001400000014000000130000000800000001686C2170686C21, null, 0) WHERE diagram_id = @id -- index:57697
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000AD0F00000100001500000015000000000000005800000001, null, 0) WHERE diagram_id = @id -- index:57729
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000073006E0061007000730068006F007400000046004B005F0045, null, 0) WHERE diagram_id = @id -- index:57761
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C0065006D0065006E00740049006E007300740061006E00630065005F0045, null, 0) WHERE diagram_id = @id -- index:57793
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C0065006D0065006E007400540079007000650000000000000000000000C4, null, 0) WHERE diagram_id = @id -- index:57825
    UPDATE sysdiagrams SET [definition] .Write ( 0x020000000016000000160000001500000008000000016C6C21706C6C21000000, null, 0) WHERE diagram_id = @id -- index:57857
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000AD0F00000100001700000017000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:57889
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000D0020000060028000000410063007400690076006500540061006200, null, 0) WHERE diagram_id = @id -- index:57921
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F0064006500000001000000080004000000, null, 0) WHERE diagram_id = @id -- index:57953
    UPDATE sysdiagrams SET [definition] .Write ( 0x31000000200000005400610062006C00650056006900650077004D006F006400, null, 0) WHERE diagram_id = @id -- index:57985
    UPDATE sysdiagrams SET [definition] .Write ( 0x65003A00300000000100000008003A00000034002C0030002C00320038003400, null, 0) WHERE diagram_id = @id -- index:58017
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0030002C0032003300310030002C0031002C0031003800390030002C003500, null, 0) WHERE diagram_id = @id -- index:58049
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0031003200360030000000200000005400610062006C006500560069006500, null, 0) WHERE diagram_id = @id -- index:58081
    UPDATE sysdiagrams SET [definition] .Write ( 0x77004D006F00640065003A00310000000100000008001E00000032002C003000, null, 0) WHERE diagram_id = @id -- index:58113
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C003200380034002C0030002C00340037003800350000002000000054006100, null, 0) WHERE diagram_id = @id -- index:58145
    UPDATE sysdiagrams SET [definition] .Write ( 0x62006C00650056006900650077004D006F00640065003A003200000001000000, null, 0) WHERE diagram_id = @id -- index:58177
    UPDATE sysdiagrams SET [definition] .Write ( 0x08001E00000032002C0030002C003200380034002C0030002C00320033003100, null, 0) WHERE diagram_id = @id -- index:58209
    UPDATE sysdiagrams SET [definition] .Write ( 0x30000000200000005400610062006C00650056006900650077004D006F006400, null, 0) WHERE diagram_id = @id -- index:58241
    UPDATE sysdiagrams SET [definition] .Write ( 0x65003A00330000000100000008001E00000032002C0030002C00320038003400, null, 0) WHERE diagram_id = @id -- index:58273
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0030002C0032003300310030000000200000005400610062006C0065005600, null, 0) WHERE diagram_id = @id -- index:58305
    UPDATE sysdiagrams SET [definition] .Write ( 0x6900650077004D006F00640065003A00340000000100000008003E0000003400, null, 0) WHERE diagram_id = @id -- index:58337
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0030002C003200380034002C0030002C0032003300310030002C0031003200, null, 0) WHERE diagram_id = @id -- index:58369
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0032003700330030002C00310031002C003100360038003000000018000000, null, 0) WHERE diagram_id = @id -- index:58401
    UPDATE sysdiagrams SET [definition] .Write ( 0x180000000000000072000000010000000100000073006E006100700073006800, null, 0) WHERE diagram_id = @id -- index:58433
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F007400000046004B005F0045006C0065006D0065006E007400540079007000, null, 0) WHERE diagram_id = @id -- index:58465
    UPDATE sysdiagrams SET [definition] .Write ( 0x650043006F006E0073007400720075006300740069006F006E004C0061007900, null, 0) WHERE diagram_id = @id -- index:58497
    UPDATE sysdiagrams SET [definition] .Write ( 0x650072005F0045006C0065006D0065006E007400540079007000650000000000, null, 0) WHERE diagram_id = @id -- index:58529
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000C402000000001900000019000000180000000800000001516C21, null, 0) WHERE diagram_id = @id -- index:58561
    UPDATE sysdiagrams SET [definition] .Write ( 0x30516C210000000000000000AD0F00000100001A0000001A0000000000000000, null, 0) WHERE diagram_id = @id -- index:58593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000D00200000600280000004100630074006900760065, null, 0) WHERE diagram_id = @id -- index:58625
    UPDATE sysdiagrams SET [definition] .Write ( 0x005400610062006C00650056006900650077004D006F00640065000000010000, null, 0) WHERE diagram_id = @id -- index:58657
    UPDATE sysdiagrams SET [definition] .Write ( 0x0008000400000031000000200000005400610062006C00650056006900650077, null, 0) WHERE diagram_id = @id -- index:58689
    UPDATE sysdiagrams SET [definition] .Write ( 0x004D006F00640065003A00300000000100000008003A00000034002C0030002C, null, 0) WHERE diagram_id = @id -- index:58721
    UPDATE sysdiagrams SET [definition] .Write ( 0x003200380034002C0030002C0032003300310030002C0031002C003100380039, null, 0) WHERE diagram_id = @id -- index:58753
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C0035002C0031003200360030000000200000005400610062006C0065, null, 0) WHERE diagram_id = @id -- index:58785
    UPDATE sysdiagrams SET [definition] .Write ( 0x0056006900650077004D006F00640065003A00310000000100000008001E0000, null, 0) WHERE diagram_id = @id -- index:58817
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032002C0030002C003200380034002C0030002C003200380036003500000020, null, 0) WHERE diagram_id = @id -- index:58849
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000005400610062006C00650056006900650077004D006F00640065003A0032, null, 0) WHERE diagram_id = @id -- index:58881
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000008001E00000032002C0030002C003200380034002C0030002C, null, 0) WHERE diagram_id = @id -- index:58913
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032003300310030000000200000005400610062006C00650056006900650077, null, 0) WHERE diagram_id = @id -- index:58945
    UPDATE sysdiagrams SET [definition] .Write ( 0x004D006F00640065003A00330000000100000008001E00000032002C0030002C, null, 0) WHERE diagram_id = @id -- index:58977
    UPDATE sysdiagrams SET [definition] .Write ( 0x003200380034002C0030002C0032003300310030000000200000005400610062, null, 0) WHERE diagram_id = @id -- index:59009
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C00650056006900650077004D006F00640065003A00340000000100000008, null, 0) WHERE diagram_id = @id -- index:59041
    UPDATE sysdiagrams SET [definition] .Write ( 0x003E00000034002C0030002C003200380034002C0030002C0032003300310030, null, 0) WHERE diagram_id = @id -- index:59073
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C00310032002C0032003700330030002C00310031002C0031003600380030, null, 0) WHERE diagram_id = @id -- index:59105
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000001B0000001B0000000000000070000000013FBC580100000073006E0061, null, 0) WHERE diagram_id = @id -- index:59137
    UPDATE sysdiagrams SET [definition] .Write ( 0x007000730068006F007400000046004B005F00470072006F007500700049006E, null, 0) WHERE diagram_id = @id -- index:59169
    UPDATE sysdiagrams SET [definition] .Write ( 0x007300740061006E00630065005F0045006C0065006D0065006E00740049006E, null, 0) WHERE diagram_id = @id -- index:59201
    UPDATE sysdiagrams SET [definition] .Write ( 0x007300740061006E00630065005F004F0077006E006500720056006900650077, null, 0) WHERE diagram_id = @id -- index:59233
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000C402000000001C0000001C0000001B000000080000, null, 0) WHERE diagram_id = @id -- index:59265
    UPDATE sysdiagrams SET [definition] .Write ( 0x0001516C21F0516C210000000000000000AD0F00000100001D0000001D000000, null, 0) WHERE diagram_id = @id -- index:59297
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000068000000010968000100000073006E0061007000730068006F007400, null, 0) WHERE diagram_id = @id -- index:59329
    UPDATE sysdiagrams SET [definition] .Write ( 0x000046004B005F00470072006F007500700049006E007300740061006E006300, null, 0) WHERE diagram_id = @id -- index:59361
    UPDATE sysdiagrams SET [definition] .Write ( 0x65005F0045006C0065006D0065006E00740049006E007300740061006E006300, null, 0) WHERE diagram_id = @id -- index:59393
    UPDATE sysdiagrams SET [definition] .Write ( 0x65005F004C006500760065006C0000000000000000000000C402000000001E00, null, 0) WHERE diagram_id = @id -- index:59425
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001E0000001D0000000800000001526C21B0526C210000000000000000AD0F, null, 0) WHERE diagram_id = @id -- index:59457
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100001F0000001F00000000000000000000000000000000000000D00200, null, 0) WHERE diagram_id = @id -- index:59489
    UPDATE sysdiagrams SET [definition] .Write ( 0x000600280000004100630074006900760065005400610062006C006500560069, null, 0) WHERE diagram_id = @id -- index:59521
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650077004D006F006400650000000100000008000400000031000000200000, null, 0) WHERE diagram_id = @id -- index:59553
    UPDATE sysdiagrams SET [definition] .Write ( 0x005400610062006C00650056006900650077004D006F00640065003A00300000, null, 0) WHERE diagram_id = @id -- index:59585
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100000008003A00000034002C0030002C003200380034002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:59617
    UPDATE sysdiagrams SET [definition] .Write ( 0x003300310030002C0031002C0031003800390030002C0035002C003100320036, null, 0) WHERE diagram_id = @id -- index:59649
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030000000200000005400610062006C00650056006900650077004D006F0064, null, 0) WHERE diagram_id = @id -- index:59681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065003A00310000000100000008001E00000032002C0030002C003200380034, null, 0) WHERE diagram_id = @id -- index:59713
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0030002C0035003600340030000000200000005400610062006C00650056, null, 0) WHERE diagram_id = @id -- index:59745
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900650077004D006F00640065003A00320000000100000008001E00000032, null, 0) WHERE diagram_id = @id -- index:59777
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0030002C003200380034002C0030002C0032003300310030000000200000, null, 0) WHERE diagram_id = @id -- index:59809
    UPDATE sysdiagrams SET [definition] .Write ( 0x005400610062006C00650056006900650077004D006F00640065003A00330000, null, 0) WHERE diagram_id = @id -- index:59841
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100000008001E00000032002C0030002C003200380034002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:59873
    UPDATE sysdiagrams SET [definition] .Write ( 0x003300310030000000200000005400610062006C00650056006900650077004D, null, 0) WHERE diagram_id = @id -- index:59905
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00640065003A00340000000100000008003E00000034002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:59937
    UPDATE sysdiagrams SET [definition] .Write ( 0x00380034002C0030002C0032003300310030002C00310032002C003200370033, null, 0) WHERE diagram_id = @id -- index:59969
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C00310031002C00310036003800300000002000000020000000000000, null, 0) WHERE diagram_id = @id -- index:60001
    UPDATE sysdiagrams SET [definition] .Write ( 0x0086000000010000000100000073006E0061007000730068006F007400000046, null, 0) WHERE diagram_id = @id -- index:60033
    UPDATE sysdiagrams SET [definition] .Write ( 0x004B005F00470072006F007500700049006E007300740061006E006300650045, null, 0) WHERE diagram_id = @id -- index:60065
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C0065006D0065006E00740049006E007300740061006E00630065004C006F, null, 0) WHERE diagram_id = @id -- index:60097
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F006B00750070005F0045006C0065006D0065006E00740049006E00730074, null, 0) WHERE diagram_id = @id -- index:60129
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061006E006300650000000000000000000000C4020000000021000000210000, null, 0) WHERE diagram_id = @id -- index:60161
    UPDATE sysdiagrams SET [definition] .Write ( 0x002000000008000000014D6C21704D6C210000000000000000AD0F0000010000, null, 0) WHERE diagram_id = @id -- index:60193
    UPDATE sysdiagrams SET [definition] .Write ( 0x22000000220000000000000082000000010040400100000073006E0061007000, null, 0) WHERE diagram_id = @id -- index:60225
    UPDATE sysdiagrams SET [definition] .Write ( 0x730068006F007400000046004B005F00470072006F007500700049006E007300, null, 0) WHERE diagram_id = @id -- index:60257
    UPDATE sysdiagrams SET [definition] .Write ( 0x740061006E006300650045006C0065006D0065006E00740049006E0073007400, null, 0) WHERE diagram_id = @id -- index:60289
    UPDATE sysdiagrams SET [definition] .Write ( 0x61006E00630065004C006F006F006B00750070005F00470072006F0075007000, null, 0) WHERE diagram_id = @id -- index:60321
    UPDATE sysdiagrams SET [definition] .Write ( 0x49006E007300740061006E006300650000000000000000000000C40200000000, null, 0) WHERE diagram_id = @id -- index:60353
    UPDATE sysdiagrams SET [definition] .Write ( 0x23000000230000002200000008000000014F6C21704F6C210000000000000000, null, 0) WHERE diagram_id = @id -- index:60385
    UPDATE sysdiagrams SET [definition] .Write ( 0xAD0F0000010000240000002400000000000000000000000000000000000000D0, null, 0) WHERE diagram_id = @id -- index:60417
    UPDATE sysdiagrams SET [definition] .Write ( 0x0200000600280000004100630074006900760065005400610062006C00650056, null, 0) WHERE diagram_id = @id -- index:60449
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900650077004D006F00640065000000010000000800040000003100000020, null, 0) WHERE diagram_id = @id -- index:60481
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000005400610062006C00650056006900650077004D006F00640065003A0030, null, 0) WHERE diagram_id = @id -- index:60513
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000008003A00000034002C0030002C003200380034002C0030002C, null, 0) WHERE diagram_id = @id -- index:60545
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032003300310030002C0031002C0031003800390030002C0035002C00310032, null, 0) WHERE diagram_id = @id -- index:60577
    UPDATE sysdiagrams SET [definition] .Write ( 0x00360030000000200000005400610062006C00650056006900650077004D006F, null, 0) WHERE diagram_id = @id -- index:60609
    UPDATE sysdiagrams SET [definition] .Write ( 0x00640065003A00310000000100000008001E00000032002C0030002C00320038, null, 0) WHERE diagram_id = @id -- index:60641
    UPDATE sysdiagrams SET [definition] .Write ( 0x0034002C0030002C0033003100380030000000200000005400610062006C0065, null, 0) WHERE diagram_id = @id -- index:60673
    UPDATE sysdiagrams SET [definition] .Write ( 0x0056006900650077004D006F00640065003A00320000000100000008001E0000, null, 0) WHERE diagram_id = @id -- index:60705
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032002C0030002C003200380034002C0030002C003200330031003000000020, null, 0) WHERE diagram_id = @id -- index:60737
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000005400610062006C00650056006900650077004D006F00640065003A0033, null, 0) WHERE diagram_id = @id -- index:60769
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000008001E00000032002C0030002C003200380034002C0030002C, null, 0) WHERE diagram_id = @id -- index:60801
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032003300310030000000200000005400610062006C00650056006900650077, null, 0) WHERE diagram_id = @id -- index:60833
    UPDATE sysdiagrams SET [definition] .Write ( 0x004D006F00640065003A00340000000100000008003E00000034002C0030002C, null, 0) WHERE diagram_id = @id -- index:60865
    UPDATE sysdiagrams SET [definition] .Write ( 0x003200380034002C0030002C0032003300310030002C00310032002C00320037, null, 0) WHERE diagram_id = @id -- index:60897
    UPDATE sysdiagrams SET [definition] .Write ( 0x00330030002C00310031002C0031003600380030000000250000002500000000, null, 0) WHERE diagram_id = @id -- index:60929
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000076000000010000000100000073006E0061007000730068006F00740000, null, 0) WHERE diagram_id = @id -- index:60961
    UPDATE sysdiagrams SET [definition] .Write ( 0x0046004B005F00470072006F007500700049006E007300740061006E00630065, null, 0) WHERE diagram_id = @id -- index:60993
    UPDATE sysdiagrams SET [definition] .Write ( 0x0050006100720061006D006500740065007200560061006C00750065005F0047, null, 0) WHERE diagram_id = @id -- index:61025
    UPDATE sysdiagrams SET [definition] .Write ( 0x0072006F007500700049006E007300740061006E006300650031000000000000, null, 0) WHERE diagram_id = @id -- index:61057
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000C402000000002600000026000000250000000800000001506C2130, null, 0) WHERE diagram_id = @id -- index:61089
    UPDATE sysdiagrams SET [definition] .Write ( 0x506C210000000000000000AD0F00000100002700000027000000000000000000, null, 0) WHERE diagram_id = @id -- index:61121
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000D0020000060028000000410063007400690076006500, null, 0) WHERE diagram_id = @id -- index:61153
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F0064006500000001000000, null, 0) WHERE diagram_id = @id -- index:61185
    UPDATE sysdiagrams SET [definition] .Write ( 0x08000400000031000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:61217
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00300000000100000008003A00000034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:61249
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C0032003300310030002C0031002C00310038003900, null, 0) WHERE diagram_id = @id -- index:61281
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0035002C0031003200360030000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:61313
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00310000000100000008001E000000, null, 0) WHERE diagram_id = @id -- index:61345
    UPDATE sysdiagrams SET [definition] .Write ( 0x32002C0030002C003200380034002C0030002C00320038003000350000002000, null, 0) WHERE diagram_id = @id -- index:61377
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005400610062006C00650056006900650077004D006F00640065003A003200, null, 0) WHERE diagram_id = @id -- index:61409
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000008001E00000032002C0030002C003200380034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:61441
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003300310030000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:61473
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00330000000100000008001E00000032002C0030002C00, null, 0) WHERE diagram_id = @id -- index:61505
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C003200330031003000000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:61537
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0034000000010000000800, null, 0) WHERE diagram_id = @id -- index:61569
    UPDATE sysdiagrams SET [definition] .Write ( 0x3E00000034002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:61601
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C00310032002C0032003700330030002C00310031002C003100360038003000, null, 0) WHERE diagram_id = @id -- index:61633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000280000002800000000000000000000000000000000000000D00200000600, null, 0) WHERE diagram_id = @id -- index:61665
    UPDATE sysdiagrams SET [definition] .Write ( 0x280000004100630074006900760065005400610062006C006500560069006500, null, 0) WHERE diagram_id = @id -- index:61697
    UPDATE sysdiagrams SET [definition] .Write ( 0x77004D006F006400650000000100000008000400000031000000200000005400, null, 0) WHERE diagram_id = @id -- index:61729
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00300000000100, null, 0) WHERE diagram_id = @id -- index:61761
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008003A00000034002C0030002C003200380034002C0030002C0032003300, null, 0) WHERE diagram_id = @id -- index:61793
    UPDATE sysdiagrams SET [definition] .Write ( 0x310030002C0031002C0031003800390030002C0035002C003100320036003000, null, 0) WHERE diagram_id = @id -- index:61825
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000200000005400610062006C00650056006900650077004D006F0064006500, null, 0) WHERE diagram_id = @id -- index:61857
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00310000000100000008001E00000032002C0030002C003200380034002C00, null, 0) WHERE diagram_id = @id -- index:61889
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0032003800300035000000200000005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:61921
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065003A00320000000100000008001E00000032002C00, null, 0) WHERE diagram_id = @id -- index:61953
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C003200380034002C0030002C0032003300310030000000200000005400, null, 0) WHERE diagram_id = @id -- index:61985
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00330000000100, null, 0) WHERE diagram_id = @id -- index:62017
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008001E00000032002C0030002C003200380034002C0030002C0032003300, null, 0) WHERE diagram_id = @id -- index:62049
    UPDATE sysdiagrams SET [definition] .Write ( 0x310030000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:62081
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00340000000100000008003E00000034002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:62113
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030002C00310032002C003200370033003000, null, 0) WHERE diagram_id = @id -- index:62145
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C00310031002C00310036003800300000002900000029000000000000000000, null, 0) WHERE diagram_id = @id -- index:62177
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000D0020000060028000000410063007400690076006500, null, 0) WHERE diagram_id = @id -- index:62209
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F0064006500000001000000, null, 0) WHERE diagram_id = @id -- index:62241
    UPDATE sysdiagrams SET [definition] .Write ( 0x08000400000031000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:62273
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00300000000100000008003A00000034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:62305
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C0032003300310030002C0031002C00310038003900, null, 0) WHERE diagram_id = @id -- index:62337
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0035002C0031003200360030000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:62369
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00310000000100000008001E000000, null, 0) WHERE diagram_id = @id -- index:62401
    UPDATE sysdiagrams SET [definition] .Write ( 0x32002C0030002C003200380034002C0030002C00320038003000350000002000, null, 0) WHERE diagram_id = @id -- index:62433
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005400610062006C00650056006900650077004D006F00640065003A003200, null, 0) WHERE diagram_id = @id -- index:62465
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000008001E00000032002C0030002C003200380034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:62497
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003300310030000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:62529
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00330000000100000008001E00000032002C0030002C00, null, 0) WHERE diagram_id = @id -- index:62561
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C003200330031003000000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:62593
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0034000000010000000800, null, 0) WHERE diagram_id = @id -- index:62625
    UPDATE sysdiagrams SET [definition] .Write ( 0x3E00000034002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:62657
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C00310032002C0032003700330030002C00310031002C003100360038003000, null, 0) WHERE diagram_id = @id -- index:62689
    UPDATE sysdiagrams SET [definition] .Write ( 0x00002A0000002A00000000000000000000000000000000000000D00200000600, null, 0) WHERE diagram_id = @id -- index:62721
    UPDATE sysdiagrams SET [definition] .Write ( 0x280000004100630074006900760065005400610062006C006500560069006500, null, 0) WHERE diagram_id = @id -- index:62753
    UPDATE sysdiagrams SET [definition] .Write ( 0x77004D006F006400650000000100000008000400000031000000200000005400, null, 0) WHERE diagram_id = @id -- index:62785
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00300000000100, null, 0) WHERE diagram_id = @id -- index:62817
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008003A00000034002C0030002C003200380034002C0030002C0032003300, null, 0) WHERE diagram_id = @id -- index:62849
    UPDATE sysdiagrams SET [definition] .Write ( 0x310030002C0031002C0031003800390030002C0035002C003100320036003000, null, 0) WHERE diagram_id = @id -- index:62881
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000200000005400610062006C00650056006900650077004D006F0064006500, null, 0) WHERE diagram_id = @id -- index:62913
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00310000000100000008001E00000032002C0030002C003200380034002C00, null, 0) WHERE diagram_id = @id -- index:62945
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0032003800300035000000200000005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:62977
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065003A00320000000100000008001E00000032002C00, null, 0) WHERE diagram_id = @id -- index:63009
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C003200380034002C0030002C0032003300310030000000200000005400, null, 0) WHERE diagram_id = @id -- index:63041
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00330000000100, null, 0) WHERE diagram_id = @id -- index:63073
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008001E00000032002C0030002C003200380034002C0030002C0032003300, null, 0) WHERE diagram_id = @id -- index:63105
    UPDATE sysdiagrams SET [definition] .Write ( 0x310030000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:63137
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00340000000100000008003E00000034002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:63169
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030002C00310032002C003200370033003000, null, 0) WHERE diagram_id = @id -- index:63201
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C00310031002C00310036003800300000002B0000002B000000000000004400, null, 0) WHERE diagram_id = @id -- index:63233
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000110B26E01000000700061006C00000046004B005F004C006F0067004100, null, 0) WHERE diagram_id = @id -- index:63265
    UPDATE sysdiagrams SET [definition] .Write ( 0x6400640049006E005F004C006F00670044006F00630053006500730073006900, null, 0) WHERE diagram_id = @id -- index:63297
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F006E0000000000000000000000C402000000002C0000002C0000002B000000, null, 0) WHERE diagram_id = @id -- index:63329
    UPDATE sysdiagrams SET [definition] .Write ( 0x08000000019F5621609F56210000000000000000AD0F00000100002D0000002D, null, 0) WHERE diagram_id = @id -- index:63361
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000440000000100000001000000700061006C00000046004B005F, null, 0) WHERE diagram_id = @id -- index:63393
    UPDATE sysdiagrams SET [definition] .Write ( 0x004C006F006700430072006100730068005F004C006F00670044006F00630053, null, 0) WHERE diagram_id = @id -- index:63425
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065007300730069006F006E0000000000000000000000C402000000002E0000, null, 0) WHERE diagram_id = @id -- index:63457
    UPDATE sysdiagrams SET [definition] .Write ( 0x002E0000002D00000008000000019F5621E09F56210000000000000000AD0F00, null, 0) WHERE diagram_id = @id -- index:63489
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100002F0000002F00000000000000000000000000000000000000D0020000, null, 0) WHERE diagram_id = @id -- index:63521
    UPDATE sysdiagrams SET [definition] .Write ( 0x0600280000004100630074006900760065005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:63553
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065000000010000000800040000003100000020000000, null, 0) WHERE diagram_id = @id -- index:63585
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F00640065003A0030000000, null, 0) WHERE diagram_id = @id -- index:63617
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000008003A00000034002C0030002C003200380034002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:63649
    UPDATE sysdiagrams SET [definition] .Write ( 0x3300310030002C0031002C0031003800390030002C0035002C00310032003600, null, 0) WHERE diagram_id = @id -- index:63681
    UPDATE sysdiagrams SET [definition] .Write ( 0x30000000200000005400610062006C00650056006900650077004D006F006400, null, 0) WHERE diagram_id = @id -- index:63713
    UPDATE sysdiagrams SET [definition] .Write ( 0x65003A00310000000100000008001E00000032002C0030002C00320038003400, null, 0) WHERE diagram_id = @id -- index:63745
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0030002C0033003400380030000000200000005400610062006C0065005600, null, 0) WHERE diagram_id = @id -- index:63777
    UPDATE sysdiagrams SET [definition] .Write ( 0x6900650077004D006F00640065003A00320000000100000008001E0000003200, null, 0) WHERE diagram_id = @id -- index:63809
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0030002C003200380034002C0030002C003200330031003000000020000000, null, 0) WHERE diagram_id = @id -- index:63841
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F00640065003A0033000000, null, 0) WHERE diagram_id = @id -- index:63873
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000008001E00000032002C0030002C003200380034002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:63905
    UPDATE sysdiagrams SET [definition] .Write ( 0x3300310030000000200000005400610062006C00650056006900650077004D00, null, 0) WHERE diagram_id = @id -- index:63937
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00640065003A00340000000100000008003E00000034002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:63969
    UPDATE sysdiagrams SET [definition] .Write ( 0x380034002C0030002C0032003300310030002C00310032002C00320037003300, null, 0) WHERE diagram_id = @id -- index:64001
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C00310031002C0031003600380030000000300000003000000000000000, null, 0) WHERE diagram_id = @id -- index:64033
    UPDATE sysdiagrams SET [definition] .Write ( 0x5E00000001010C5F01000000700061006C00000046004B005F004C006F006700, null, 0) WHERE diagram_id = @id -- index:64065
    UPDATE sysdiagrams SET [definition] .Write ( 0x44006F00630075006D0065006E007400500072006F006A004300680061006E00, null, 0) WHERE diagram_id = @id -- index:64097
    UPDATE sysdiagrams SET [definition] .Write ( 0x670065005F004C006F00670044006F006300530065007300730069006F006E00, null, 0) WHERE diagram_id = @id -- index:64129
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000C4020000000031000000310000003000000008000000, null, 0) WHERE diagram_id = @id -- index:64161
    UPDATE sysdiagrams SET [definition] .Write ( 0x019B5621E09B56210000000000000000AD0F0000010000320000003200000000, null, 0) WHERE diagram_id = @id -- index:64193
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000000D002000006002800000041006300740069, null, 0) WHERE diagram_id = @id -- index:64225
    UPDATE sysdiagrams SET [definition] .Write ( 0x00760065005400610062006C00650056006900650077004D006F006400650000, null, 0) WHERE diagram_id = @id -- index:64257
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100000008000400000031000000200000005400610062006C006500560069, null, 0) WHERE diagram_id = @id -- index:64289
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650077004D006F00640065003A00300000000100000008003A00000034002C, null, 0) WHERE diagram_id = @id -- index:64321
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C003200380034002C0030002C0032003300310030002C0031002C0031, null, 0) WHERE diagram_id = @id -- index:64353
    UPDATE sysdiagrams SET [definition] .Write ( 0x003800390030002C0035002C0031003200360030000000200000005400610062, null, 0) WHERE diagram_id = @id -- index:64385
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C00650056006900650077004D006F00640065003A00310000000100000008, null, 0) WHERE diagram_id = @id -- index:64417
    UPDATE sysdiagrams SET [definition] .Write ( 0x001E00000032002C0030002C003200380034002C0030002C0032003800300035, null, 0) WHERE diagram_id = @id -- index:64449
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000200000005400610062006C00650056006900650077004D006F00640065, null, 0) WHERE diagram_id = @id -- index:64481
    UPDATE sysdiagrams SET [definition] .Write ( 0x003A00320000000100000008001E00000032002C0030002C003200380034002C, null, 0) WHERE diagram_id = @id -- index:64513
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C0032003300310030000000200000005400610062006C006500560069, null, 0) WHERE diagram_id = @id -- index:64545
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650077004D006F00640065003A00330000000100000008001E00000032002C, null, 0) WHERE diagram_id = @id -- index:64577
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C003200380034002C0030002C00320033003100300000002000000054, null, 0) WHERE diagram_id = @id -- index:64609
    UPDATE sysdiagrams SET [definition] .Write ( 0x00610062006C00650056006900650077004D006F00640065003A003400000001, null, 0) WHERE diagram_id = @id -- index:64641
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000008003E00000034002C0030002C003200380034002C0030002C00320033, null, 0) WHERE diagram_id = @id -- index:64673
    UPDATE sysdiagrams SET [definition] .Write ( 0x00310030002C00310032002C0032003700330030002C00310031002C00310036, null, 0) WHERE diagram_id = @id -- index:64705
    UPDATE sysdiagrams SET [definition] .Write ( 0x00380030000000330000003300000000000000480000000110B26E0100000070, null, 0) WHERE diagram_id = @id -- index:64737
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061006C00000046004B005F004C006F00670045006C0065006D0065006E0074, null, 0) WHERE diagram_id = @id -- index:64769
    UPDATE sysdiagrams SET [definition] .Write ( 0x005F004C006F00670044006F006300530065007300730069006F006E00000000, null, 0) WHERE diagram_id = @id -- index:64801
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000C4020000000034000000340000003300000008000000018756, null, 0) WHERE diagram_id = @id -- index:64833
    UPDATE sysdiagrams SET [definition] .Write ( 0x21208756210000000000000000AD0F0000010000350000003500000000000000, null, 0) WHERE diagram_id = @id -- index:64865
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000D002000006002800000041006300740069007600, null, 0) WHERE diagram_id = @id -- index:64897
    UPDATE sysdiagrams SET [definition] .Write ( 0x65005400610062006C00650056006900650077004D006F006400650000000100, null, 0) WHERE diagram_id = @id -- index:64929
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008000400000031000000200000005400610062006C006500560069006500, null, 0) WHERE diagram_id = @id -- index:64961
    UPDATE sysdiagrams SET [definition] .Write ( 0x77004D006F00640065003A00300000000100000008003A00000034002C003000, null, 0) WHERE diagram_id = @id -- index:64993
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C003200380034002C0030002C0032003300310030002C0031002C0031003800, null, 0) WHERE diagram_id = @id -- index:65025
    UPDATE sysdiagrams SET [definition] .Write ( 0x390030002C0035002C0031003200360030000000200000005400610062006C00, null, 0) WHERE diagram_id = @id -- index:65057
    UPDATE sysdiagrams SET [definition] .Write ( 0x650056006900650077004D006F00640065003A00310000000100000008001E00, null, 0) WHERE diagram_id = @id -- index:65089
    UPDATE sysdiagrams SET [definition] .Write ( 0x000032002C0030002C003200380034002C0030002C0032003800300035000000, null, 0) WHERE diagram_id = @id -- index:65121
    UPDATE sysdiagrams SET [definition] .Write ( 0x200000005400610062006C00650056006900650077004D006F00640065003A00, null, 0) WHERE diagram_id = @id -- index:65153
    UPDATE sysdiagrams SET [definition] .Write ( 0x320000000100000008001E00000032002C0030002C003200380034002C003000, null, 0) WHERE diagram_id = @id -- index:65185
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0032003300310030000000200000005400610062006C006500560069006500, null, 0) WHERE diagram_id = @id -- index:65217
    UPDATE sysdiagrams SET [definition] .Write ( 0x77004D006F00640065003A00330000000100000008001E00000032002C003000, null, 0) WHERE diagram_id = @id -- index:65249
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C003200380034002C0030002C00320033003100300000002000000054006100, null, 0) WHERE diagram_id = @id -- index:65281
    UPDATE sysdiagrams SET [definition] .Write ( 0x62006C00650056006900650077004D006F00640065003A003400000001000000, null, 0) WHERE diagram_id = @id -- index:65313
    UPDATE sysdiagrams SET [definition] .Write ( 0x08003E00000034002C0030002C003200380034002C0030002C00320033003100, null, 0) WHERE diagram_id = @id -- index:65345
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C00310032002C0032003700330030002C00310031002C00310036003800, null, 0) WHERE diagram_id = @id -- index:65377
    UPDATE sysdiagrams SET [definition] .Write ( 0x30000000360000003600000000000000000000000000000000000000D0020000, null, 0) WHERE diagram_id = @id -- index:65409
    UPDATE sysdiagrams SET [definition] .Write ( 0x0600280000004100630074006900760065005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:65441
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065000000010000000800040000003100000020000000, null, 0) WHERE diagram_id = @id -- index:65473
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F00640065003A0030000000, null, 0) WHERE diagram_id = @id -- index:65505
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000008003A00000034002C0030002C003200380034002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:65537
    UPDATE sysdiagrams SET [definition] .Write ( 0x3300310030002C0031002C0031003800390030002C0035002C00310032003600, null, 0) WHERE diagram_id = @id -- index:65569
    UPDATE sysdiagrams SET [definition] .Write ( 0x30000000200000005400610062006C00650056006900650077004D006F006400, null, 0) WHERE diagram_id = @id -- index:65601
    UPDATE sysdiagrams SET [definition] .Write ( 0x65003A00310000000100000008001E00000032002C0030002C00320038003400, null, 0) WHERE diagram_id = @id -- index:65633
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0030002C0032003800300035000000200000005400610062006C0065005600, null, 0) WHERE diagram_id = @id -- index:65665
    UPDATE sysdiagrams SET [definition] .Write ( 0x6900650077004D006F00640065003A00320000000100000008001E0000003200, null, 0) WHERE diagram_id = @id -- index:65697
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0030002C003200380034002C0030002C003200330031003000000020000000, null, 0) WHERE diagram_id = @id -- index:65729
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F00640065003A0033000000, null, 0) WHERE diagram_id = @id -- index:65761
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000008001E00000032002C0030002C003200380034002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:65793
    UPDATE sysdiagrams SET [definition] .Write ( 0x3300310030000000200000005400610062006C00650056006900650077004D00, null, 0) WHERE diagram_id = @id -- index:65825
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00640065003A00340000000100000008003E00000034002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:65857
    UPDATE sysdiagrams SET [definition] .Write ( 0x380034002C0030002C0032003300310030002C00310032002C00320037003300, null, 0) WHERE diagram_id = @id -- index:65889
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C00310031002C0031003600380030000000370000003700000000000000, null, 0) WHERE diagram_id = @id -- index:65921
    UPDATE sysdiagrams SET [definition] .Write ( 0x440000000110B26E01000000700061006C00000046004B005F004C006F006700, null, 0) WHERE diagram_id = @id -- index:65953
    UPDATE sysdiagrams SET [definition] .Write ( 0x4500760065006E0074005F004C006F00670044006F0063005300650073007300, null, 0) WHERE diagram_id = @id -- index:65985
    UPDATE sysdiagrams SET [definition] .Write ( 0x69006F006E0000000000000000000000C4020000000038000000380000003700, null, 0) WHERE diagram_id = @id -- index:66017
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008000000018D5621A08D56210000000000000000AD0F0000010000390000, null, 0) WHERE diagram_id = @id -- index:66049
    UPDATE sysdiagrams SET [definition] .Write ( 0x003900000000000000000000000000000000000000D002000006002800000041, null, 0) WHERE diagram_id = @id -- index:66081
    UPDATE sysdiagrams SET [definition] .Write ( 0x00630074006900760065005400610062006C00650056006900650077004D006F, null, 0) WHERE diagram_id = @id -- index:66113
    UPDATE sysdiagrams SET [definition] .Write ( 0x006400650000000100000008000400000031000000200000005400610062006C, null, 0) WHERE diagram_id = @id -- index:66145
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650056006900650077004D006F00640065003A00300000000100000008003A, null, 0) WHERE diagram_id = @id -- index:66177
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000034002C0030002C003200380034002C0030002C0032003300310030002C, null, 0) WHERE diagram_id = @id -- index:66209
    UPDATE sysdiagrams SET [definition] .Write ( 0x0031002C0031003800390030002C0035002C0031003200360030000000200000, null, 0) WHERE diagram_id = @id -- index:66241
    UPDATE sysdiagrams SET [definition] .Write ( 0x005400610062006C00650056006900650077004D006F00640065003A00310000, null, 0) WHERE diagram_id = @id -- index:66273
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100000008001E00000032002C0030002C003200380034002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:66305
    UPDATE sysdiagrams SET [definition] .Write ( 0x003800300035000000200000005400610062006C00650056006900650077004D, null, 0) WHERE diagram_id = @id -- index:66337
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00640065003A00320000000100000008001E00000032002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:66369
    UPDATE sysdiagrams SET [definition] .Write ( 0x00380034002C0030002C0032003300310030000000200000005400610062006C, null, 0) WHERE diagram_id = @id -- index:66401
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650056006900650077004D006F00640065003A00330000000100000008001E, null, 0) WHERE diagram_id = @id -- index:66433
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000032002C0030002C003200380034002C0030002C00320033003100300000, null, 0) WHERE diagram_id = @id -- index:66465
    UPDATE sysdiagrams SET [definition] .Write ( 0x00200000005400610062006C00650056006900650077004D006F00640065003A, null, 0) WHERE diagram_id = @id -- index:66497
    UPDATE sysdiagrams SET [definition] .Write ( 0x00340000000100000008003E00000034002C0030002C003200380034002C0030, null, 0) WHERE diagram_id = @id -- index:66529
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0032003300310030002C00310032002C0032003700330030002C00310031, null, 0) WHERE diagram_id = @id -- index:66561
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C00310036003800300000003A0000003A0000000000000042000000010000, null, 0) WHERE diagram_id = @id -- index:66593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0001000000700061006C00000046004B005F004C006F0067004C0069006E006B, null, 0) WHERE diagram_id = @id -- index:66625
    UPDATE sysdiagrams SET [definition] .Write ( 0x005F004C006F00670044006F006300530065007300730069006F006E00000000, null, 0) WHERE diagram_id = @id -- index:66657
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000C402000000003B0000003B0000003A00000008000000019756, null, 0) WHERE diagram_id = @id -- index:66689
    UPDATE sysdiagrams SET [definition] .Write ( 0x21A09756210000000000000000AD0F00000100003C0000003C00000000000000, null, 0) WHERE diagram_id = @id -- index:66721
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000D002000006002800000041006300740069007600, null, 0) WHERE diagram_id = @id -- index:66753
    UPDATE sysdiagrams SET [definition] .Write ( 0x65005400610062006C00650056006900650077004D006F006400650000000100, null, 0) WHERE diagram_id = @id -- index:66785
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008000400000031000000200000005400610062006C006500560069006500, null, 0) WHERE diagram_id = @id -- index:66817
    UPDATE sysdiagrams SET [definition] .Write ( 0x77004D006F00640065003A00300000000100000008003A00000034002C003000, null, 0) WHERE diagram_id = @id -- index:66849
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C003200380034002C0030002C0032003300310030002C0031002C0031003800, null, 0) WHERE diagram_id = @id -- index:66881
    UPDATE sysdiagrams SET [definition] .Write ( 0x390030002C0035002C0031003200360030000000200000005400610062006C00, null, 0) WHERE diagram_id = @id -- index:66913
    UPDATE sysdiagrams SET [definition] .Write ( 0x650056006900650077004D006F00640065003A00310000000100000008001E00, null, 0) WHERE diagram_id = @id -- index:66945
    UPDATE sysdiagrams SET [definition] .Write ( 0x000032002C0030002C003200380034002C0030002C0032003800300035000000, null, 0) WHERE diagram_id = @id -- index:66977
    UPDATE sysdiagrams SET [definition] .Write ( 0x200000005400610062006C00650056006900650077004D006F00640065003A00, null, 0) WHERE diagram_id = @id -- index:67009
    UPDATE sysdiagrams SET [definition] .Write ( 0x320000000100000008001E00000032002C0030002C003200380034002C003000, null, 0) WHERE diagram_id = @id -- index:67041
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0032003300310030000000200000005400610062006C006500560069006500, null, 0) WHERE diagram_id = @id -- index:67073
    UPDATE sysdiagrams SET [definition] .Write ( 0x77004D006F00640065003A00330000000100000008001E00000032002C003000, null, 0) WHERE diagram_id = @id -- index:67105
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C003200380034002C0030002C00320033003100300000002000000054006100, null, 0) WHERE diagram_id = @id -- index:67137
    UPDATE sysdiagrams SET [definition] .Write ( 0x62006C00650056006900650077004D006F00640065003A003400000001000000, null, 0) WHERE diagram_id = @id -- index:67169
    UPDATE sysdiagrams SET [definition] .Write ( 0x08003E00000034002C0030002C003200380034002C0030002C00320033003100, null, 0) WHERE diagram_id = @id -- index:67201
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C00310032002C0032003700330030002C00310031002C00310036003800, null, 0) WHERE diagram_id = @id -- index:67233
    UPDATE sysdiagrams SET [definition] .Write ( 0x300000003D0000003D0000000000000048000000010000000100000070006100, null, 0) WHERE diagram_id = @id -- index:67265
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00000046004B005F004C006F0067004D0061006300680069006E0065005F00, null, 0) WHERE diagram_id = @id -- index:67297
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C006F00670044006F006300530065007300730069006F006E00000000000000, null, 0) WHERE diagram_id = @id -- index:67329
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000C402000000003E0000003E0000003D0000000800000001925621A092, null, 0) WHERE diagram_id = @id -- index:67361
    UPDATE sysdiagrams SET [definition] .Write ( 0x56210000000000000000AD0F00000100003F0000003F00000000000000000000, null, 0) WHERE diagram_id = @id -- index:67393
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000D002000006002800000041006300740069007600650054, null, 0) WHERE diagram_id = @id -- index:67425
    UPDATE sysdiagrams SET [definition] .Write ( 0x00610062006C00650056006900650077004D006F006400650000000100000008, null, 0) WHERE diagram_id = @id -- index:67457
    UPDATE sysdiagrams SET [definition] .Write ( 0x000400000031000000200000005400610062006C00650056006900650077004D, null, 0) WHERE diagram_id = @id -- index:67489
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00640065003A00300000000100000008003A00000034002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:67521
    UPDATE sysdiagrams SET [definition] .Write ( 0x00380034002C0030002C0032003300310030002C0031002C0031003800390030, null, 0) WHERE diagram_id = @id -- index:67553
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0035002C0031003200360030000000200000005400610062006C00650056, null, 0) WHERE diagram_id = @id -- index:67585
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900650077004D006F00640065003A00310000000100000008001E00000032, null, 0) WHERE diagram_id = @id -- index:67617
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0030002C003200380034002C0030002C0032003800300035000000200000, null, 0) WHERE diagram_id = @id -- index:67649
    UPDATE sysdiagrams SET [definition] .Write ( 0x005400610062006C00650056006900650077004D006F00640065003A00320000, null, 0) WHERE diagram_id = @id -- index:67681
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100000008001E00000032002C0030002C003200380034002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:67713
    UPDATE sysdiagrams SET [definition] .Write ( 0x003300310030000000200000005400610062006C00650056006900650077004D, null, 0) WHERE diagram_id = @id -- index:67745
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00640065003A00330000000100000008001E00000032002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:67777
    UPDATE sysdiagrams SET [definition] .Write ( 0x00380034002C0030002C0032003300310030000000200000005400610062006C, null, 0) WHERE diagram_id = @id -- index:67809
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650056006900650077004D006F00640065003A00340000000100000008003E, null, 0) WHERE diagram_id = @id -- index:67841
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000034002C0030002C003200380034002C0030002C0032003300310030002C, null, 0) WHERE diagram_id = @id -- index:67873
    UPDATE sysdiagrams SET [definition] .Write ( 0x00310032002C0032003700330030002C00310031002C00310036003800300000, null, 0) WHERE diagram_id = @id -- index:67905
    UPDATE sysdiagrams SET [definition] .Write ( 0x00400000004000000000000000440000000100000001000000700061006C0000, null, 0) WHERE diagram_id = @id -- index:67937
    UPDATE sysdiagrams SET [definition] .Write ( 0x0046004B005F004C006F0067005000720069006E0074005F004C006F00670044, null, 0) WHERE diagram_id = @id -- index:67969
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F006300530065007300730069006F006E0000000000000000000000C40200, null, 0) WHERE diagram_id = @id -- index:68001
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000004100000041000000400000000800000001955621209556210000000000, null, 0) WHERE diagram_id = @id -- index:68033
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000AD0F000001000042000000420000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:68065
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000D00200000600280000004100630074006900760065005400610062006C00, null, 0) WHERE diagram_id = @id -- index:68097
    UPDATE sysdiagrams SET [definition] .Write ( 0x650056006900650077004D006F00640065000000010000000800040000003100, null, 0) WHERE diagram_id = @id -- index:68129
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000200000005400610062006C00650056006900650077004D006F0064006500, null, 0) WHERE diagram_id = @id -- index:68161
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00300000000100000008003A00000034002C0030002C003200380034002C00, null, 0) WHERE diagram_id = @id -- index:68193
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0032003300310030002C0031002C0031003800390030002C0035002C00, null, 0) WHERE diagram_id = @id -- index:68225
    UPDATE sysdiagrams SET [definition] .Write ( 0x31003200360030000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:68257
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00310000000100000008001E00000032002C0030002C00, null, 0) WHERE diagram_id = @id -- index:68289
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C003200380030003500000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:68321
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0032000000010000000800, null, 0) WHERE diagram_id = @id -- index:68353
    UPDATE sysdiagrams SET [definition] .Write ( 0x1E00000032002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:68385
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000200000005400610062006C00650056006900650077004D006F0064006500, null, 0) WHERE diagram_id = @id -- index:68417
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00330000000100000008001E00000032002C0030002C003200380034002C00, null, 0) WHERE diagram_id = @id -- index:68449
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0032003300310030000000200000005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:68481
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065003A00340000000100000008003E00000034002C00, null, 0) WHERE diagram_id = @id -- index:68513
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C003200380034002C0030002C0032003300310030002C00310032002C00, null, 0) WHERE diagram_id = @id -- index:68545
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003700330030002C00310031002C0031003600380030000000430000004300, null, 0) WHERE diagram_id = @id -- index:68577
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000000000000000000000000000D002000006002800000041006300, null, 0) WHERE diagram_id = @id -- index:68609
    UPDATE sysdiagrams SET [definition] .Write ( 0x74006900760065005400610062006C00650056006900650077004D006F006400, null, 0) WHERE diagram_id = @id -- index:68641
    UPDATE sysdiagrams SET [definition] .Write ( 0x650000000100000008000400000031000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:68673
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00300000000100000008003A000000, null, 0) WHERE diagram_id = @id -- index:68705
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C003200380034002C0030002C0032003300310030002C003100, null, 0) WHERE diagram_id = @id -- index:68737
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0031003800390030002C0035002C0031003200360030000000200000005400, null, 0) WHERE diagram_id = @id -- index:68769
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00310000000100, null, 0) WHERE diagram_id = @id -- index:68801
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008001E00000032002C0030002C003200380034002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:68833
    UPDATE sysdiagrams SET [definition] .Write ( 0x300035000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:68865
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00320000000100000008001E00000032002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:68897
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:68929
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00330000000100000008001E000000, null, 0) WHERE diagram_id = @id -- index:68961
    UPDATE sysdiagrams SET [definition] .Write ( 0x32002C0030002C003200380034002C0030002C00320033003100300000002000, null, 0) WHERE diagram_id = @id -- index:68993
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005400610062006C00650056006900650077004D006F00640065003A003400, null, 0) WHERE diagram_id = @id -- index:69025
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000008003E00000034002C0030002C003200380034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:69057
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003300310030002C00310032002C0032003700330030002C00310031002C00, null, 0) WHERE diagram_id = @id -- index:69089
    UPDATE sysdiagrams SET [definition] .Write ( 0x3100360038003000000044000000440000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:69121
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000D00200000600280000004100630074006900760065005400610062006C00, null, 0) WHERE diagram_id = @id -- index:69153
    UPDATE sysdiagrams SET [definition] .Write ( 0x650056006900650077004D006F00640065000000010000000800040000003100, null, 0) WHERE diagram_id = @id -- index:69185
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000200000005400610062006C00650056006900650077004D006F0064006500, null, 0) WHERE diagram_id = @id -- index:69217
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00300000000100000008003A00000034002C0030002C003200380034002C00, null, 0) WHERE diagram_id = @id -- index:69249
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0032003300310030002C0031002C0031003800390030002C0035002C00, null, 0) WHERE diagram_id = @id -- index:69281
    UPDATE sysdiagrams SET [definition] .Write ( 0x31003200360030000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:69313
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00310000000100000008001E00000032002C0030002C00, null, 0) WHERE diagram_id = @id -- index:69345
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C003200380030003500000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:69377
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0032000000010000000800, null, 0) WHERE diagram_id = @id -- index:69409
    UPDATE sysdiagrams SET [definition] .Write ( 0x1E00000032002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:69441
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000200000005400610062006C00650056006900650077004D006F0064006500, null, 0) WHERE diagram_id = @id -- index:69473
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00330000000100000008001E00000032002C0030002C003200380034002C00, null, 0) WHERE diagram_id = @id -- index:69505
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0032003300310030000000200000005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:69537
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065003A00340000000100000008003E00000034002C00, null, 0) WHERE diagram_id = @id -- index:69569
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C003200380034002C0030002C0032003300310030002C00310032002C00, null, 0) WHERE diagram_id = @id -- index:69601
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003700330030002C00310031002C0031003600380030000000450000004500, null, 0) WHERE diagram_id = @id -- index:69633
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000480000000110B26E01000000700061006C00000046004B005F00, null, 0) WHERE diagram_id = @id -- index:69665
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C006F006700530075006D006D006100720079005F004C006F00670044006F00, null, 0) WHERE diagram_id = @id -- index:69697
    UPDATE sysdiagrams SET [definition] .Write ( 0x6300530065007300730069006F006E0000000000000000000000C40200000000, null, 0) WHERE diagram_id = @id -- index:69729
    UPDATE sysdiagrams SET [definition] .Write ( 0x4600000046000000450000000800000001975621209756210000000000000000, null, 0) WHERE diagram_id = @id -- index:69761
    UPDATE sysdiagrams SET [definition] .Write ( 0xAD0F0000010000470000004700000000000000000000000000000000000000D0, null, 0) WHERE diagram_id = @id -- index:69793
    UPDATE sysdiagrams SET [definition] .Write ( 0x0200000600280000004100630074006900760065005400610062006C00650056, null, 0) WHERE diagram_id = @id -- index:69825
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900650077004D006F00640065000000010000000800040000003100000020, null, 0) WHERE diagram_id = @id -- index:69857
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000005400610062006C00650056006900650077004D006F00640065003A0030, null, 0) WHERE diagram_id = @id -- index:69889
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000008003A00000034002C0030002C003200380034002C0030002C, null, 0) WHERE diagram_id = @id -- index:69921
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032003300310030002C0031002C0031003800390030002C0035002C00310032, null, 0) WHERE diagram_id = @id -- index:69953
    UPDATE sysdiagrams SET [definition] .Write ( 0x00360030000000200000005400610062006C00650056006900650077004D006F, null, 0) WHERE diagram_id = @id -- index:69985
    UPDATE sysdiagrams SET [definition] .Write ( 0x00640065003A00310000000100000008001E00000032002C0030002C00320038, null, 0) WHERE diagram_id = @id -- index:70017
    UPDATE sysdiagrams SET [definition] .Write ( 0x0034002C0030002C0032003800300035000000200000005400610062006C0065, null, 0) WHERE diagram_id = @id -- index:70049
    UPDATE sysdiagrams SET [definition] .Write ( 0x0056006900650077004D006F00640065003A00320000000100000008001E0000, null, 0) WHERE diagram_id = @id -- index:70081
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032002C0030002C003200380034002C0030002C003200330031003000000020, null, 0) WHERE diagram_id = @id -- index:70113
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000005400610062006C00650056006900650077004D006F00640065003A0033, null, 0) WHERE diagram_id = @id -- index:70145
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000008001E00000032002C0030002C003200380034002C0030002C, null, 0) WHERE diagram_id = @id -- index:70177
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032003300310030000000200000005400610062006C00650056006900650077, null, 0) WHERE diagram_id = @id -- index:70209
    UPDATE sysdiagrams SET [definition] .Write ( 0x004D006F00640065003A00340000000100000008003E00000034002C0030002C, null, 0) WHERE diagram_id = @id -- index:70241
    UPDATE sysdiagrams SET [definition] .Write ( 0x003200380034002C0030002C0032003300310030002C00310032002C00320037, null, 0) WHERE diagram_id = @id -- index:70273
    UPDATE sysdiagrams SET [definition] .Write ( 0x00330030002C00310031002C0031003600380030000000480000004800000000, null, 0) WHERE diagram_id = @id -- index:70305
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000004A000000013FBC5801000000700061006C00000046004B005F004C006F, null, 0) WHERE diagram_id = @id -- index:70337
    UPDATE sysdiagrams SET [definition] .Write ( 0x006700560069006500770054007900700065005F004C006F00670044006F0063, null, 0) WHERE diagram_id = @id -- index:70369
    UPDATE sysdiagrams SET [definition] .Write ( 0x00530065007300730069006F006E0000000000000000000000C4020000000049, null, 0) WHERE diagram_id = @id -- index:70401
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000049000000480000000800000001BD1D2198BD1D210000000000000000AD, null, 0) WHERE diagram_id = @id -- index:70433
    UPDATE sysdiagrams SET [definition] .Write ( 0x0F00000100004A0000004A00000000000000000000000000000000000000D002, null, 0) WHERE diagram_id = @id -- index:70465
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000600280000004100630074006900760065005400610062006C0065005600, null, 0) WHERE diagram_id = @id -- index:70497
    UPDATE sysdiagrams SET [definition] .Write ( 0x6900650077004D006F0064006500000001000000080004000000310000002000, null, 0) WHERE diagram_id = @id -- index:70529
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005400610062006C00650056006900650077004D006F00640065003A003000, null, 0) WHERE diagram_id = @id -- index:70561
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000008003A00000034002C0030002C003200380034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:70593
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003300310030002C0031002C0031003800390030002C0035002C0031003200, null, 0) WHERE diagram_id = @id -- index:70625
    UPDATE sysdiagrams SET [definition] .Write ( 0x360030000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:70657
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00310000000100000008001E00000032002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:70689
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003800300035000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:70721
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00320000000100000008001E000000, null, 0) WHERE diagram_id = @id -- index:70753
    UPDATE sysdiagrams SET [definition] .Write ( 0x32002C0030002C003200380034002C0030002C00320033003100300000002000, null, 0) WHERE diagram_id = @id -- index:70785
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005400610062006C00650056006900650077004D006F00640065003A003300, null, 0) WHERE diagram_id = @id -- index:70817
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000008001E00000032002C0030002C003200380034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:70849
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003300310030000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:70881
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00340000000100000008003E00000034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:70913
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C0032003300310030002C00310032002C0032003700, null, 0) WHERE diagram_id = @id -- index:70945
    UPDATE sysdiagrams SET [definition] .Write ( 0x330030002C00310031002C00310036003800300000004B0000004B0000000000, null, 0) WHERE diagram_id = @id -- index:70977
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000480000000110B26E01000000700061006C00000046004B005F004C006F00, null, 0) WHERE diagram_id = @id -- index:71009
    UPDATE sysdiagrams SET [definition] .Write ( 0x67005700610072006E0069006E0067005F004C006F00670044006F0063005300, null, 0) WHERE diagram_id = @id -- index:71041
    UPDATE sysdiagrams SET [definition] .Write ( 0x65007300730069006F006E0000000000000000000000C402000000004C000000, null, 0) WHERE diagram_id = @id -- index:71073
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C0000004B0000000800000001BE1D21D8BE1D210000000000000000AD0F0000, null, 0) WHERE diagram_id = @id -- index:71105
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100004D0000004D00000000000000000000000000000000000000D002000006, null, 0) WHERE diagram_id = @id -- index:71137
    UPDATE sysdiagrams SET [definition] .Write ( 0x00280000004100630074006900760065005400610062006C0065005600690065, null, 0) WHERE diagram_id = @id -- index:71169
    UPDATE sysdiagrams SET [definition] .Write ( 0x0077004D006F0064006500000001000000080004000000310000002000000054, null, 0) WHERE diagram_id = @id -- index:71201
    UPDATE sysdiagrams SET [definition] .Write ( 0x00610062006C00650056006900650077004D006F00640065003A003000000001, null, 0) WHERE diagram_id = @id -- index:71233
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000008003A00000034002C0030002C003200380034002C0030002C00320033, null, 0) WHERE diagram_id = @id -- index:71265
    UPDATE sysdiagrams SET [definition] .Write ( 0x00310030002C0031002C0031003800390030002C0035002C0031003200360030, null, 0) WHERE diagram_id = @id -- index:71297
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000200000005400610062006C00650056006900650077004D006F00640065, null, 0) WHERE diagram_id = @id -- index:71329
    UPDATE sysdiagrams SET [definition] .Write ( 0x003A00310000000100000008001E00000032002C0030002C003200380034002C, null, 0) WHERE diagram_id = @id -- index:71361
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C0033003000330030000000200000005400610062006C006500560069, null, 0) WHERE diagram_id = @id -- index:71393
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650077004D006F00640065003A00320000000100000008001E00000032002C, null, 0) WHERE diagram_id = @id -- index:71425
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C003200380034002C0030002C00320033003100300000002000000054, null, 0) WHERE diagram_id = @id -- index:71457
    UPDATE sysdiagrams SET [definition] .Write ( 0x00610062006C00650056006900650077004D006F00640065003A003300000001, null, 0) WHERE diagram_id = @id -- index:71489
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000008001E00000032002C0030002C003200380034002C0030002C00320033, null, 0) WHERE diagram_id = @id -- index:71521
    UPDATE sysdiagrams SET [definition] .Write ( 0x00310030000000200000005400610062006C00650056006900650077004D006F, null, 0) WHERE diagram_id = @id -- index:71553
    UPDATE sysdiagrams SET [definition] .Write ( 0x00640065003A00340000000100000008003E00000034002C0030002C00320038, null, 0) WHERE diagram_id = @id -- index:71585
    UPDATE sysdiagrams SET [definition] .Write ( 0x0034002C0030002C0032003300310030002C00310032002C0032003700330030, null, 0) WHERE diagram_id = @id -- index:71617
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C00310031002C00310036003800300000004E0000004E0000000000000056, null, 0) WHERE diagram_id = @id -- index:71649
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000001000000700061006C00000046004B005F004C006F00670057, null, 0) WHERE diagram_id = @id -- index:71681
    UPDATE sysdiagrams SET [definition] .Write ( 0x00610072006E0069006E006700530075006D006D006100720079005F004C006F, null, 0) WHERE diagram_id = @id -- index:71713
    UPDATE sysdiagrams SET [definition] .Write ( 0x00670044006F006300530065007300730069006F006E00000000000000000000, null, 0) WHERE diagram_id = @id -- index:71745
    UPDATE sysdiagrams SET [definition] .Write ( 0x00C402000000004F0000004F0000004E0000000800000001BA1D2118BA1D2100, null, 0) WHERE diagram_id = @id -- index:71777
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000AD0F0000010000500000005000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:71809
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000D002000006002800000041006300740069007600650054006100, null, 0) WHERE diagram_id = @id -- index:71841
    UPDATE sysdiagrams SET [definition] .Write ( 0x62006C00650056006900650077004D006F006400650000000100000008000400, null, 0) WHERE diagram_id = @id -- index:71873
    UPDATE sysdiagrams SET [definition] .Write ( 0x000031000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:71905
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00300000000100000008003A00000034002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:71937
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030002C0031002C0031003800390030002C00, null, 0) WHERE diagram_id = @id -- index:71969
    UPDATE sysdiagrams SET [definition] .Write ( 0x35002C0031003200360030000000200000005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:72001
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065003A00310000000100000008001E00000032002C00, null, 0) WHERE diagram_id = @id -- index:72033
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C003200380034002C0030002C0032003800300035000000200000005400, null, 0) WHERE diagram_id = @id -- index:72065
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00320000000100, null, 0) WHERE diagram_id = @id -- index:72097
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008001E00000032002C0030002C003200380034002C0030002C0032003300, null, 0) WHERE diagram_id = @id -- index:72129
    UPDATE sysdiagrams SET [definition] .Write ( 0x310030000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:72161
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00330000000100000008001E00000032002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:72193
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:72225
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00340000000100000008003E000000, null, 0) WHERE diagram_id = @id -- index:72257
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C003200380034002C0030002C0032003300310030002C003100, null, 0) WHERE diagram_id = @id -- index:72289
    UPDATE sysdiagrams SET [definition] .Write ( 0x32002C0032003700330030002C00310031002C00310036003800300000005100, null, 0) WHERE diagram_id = @id -- index:72321
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005100000000000000000000000000000000000000D0020000060028000000, null, 0) WHERE diagram_id = @id -- index:72353
    UPDATE sysdiagrams SET [definition] .Write ( 0x4100630074006900760065005400610062006C00650056006900650077004D00, null, 0) WHERE diagram_id = @id -- index:72385
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00640065000000010000000800040000003100000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:72417
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0030000000010000000800, null, 0) WHERE diagram_id = @id -- index:72449
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00000034002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:72481
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0031002C0031003800390030002C0035002C00310032003600300000002000, null, 0) WHERE diagram_id = @id -- index:72513
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005400610062006C00650056006900650077004D006F00640065003A003100, null, 0) WHERE diagram_id = @id -- index:72545
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000008001E00000032002C0030002C003200380034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:72577
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003800300035000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:72609
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00320000000100000008001E00000032002C0030002C00, null, 0) WHERE diagram_id = @id -- index:72641
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C003200330031003000000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:72673
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0033000000010000000800, null, 0) WHERE diagram_id = @id -- index:72705
    UPDATE sysdiagrams SET [definition] .Write ( 0x1E00000032002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:72737
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000200000005400610062006C00650056006900650077004D006F0064006500, null, 0) WHERE diagram_id = @id -- index:72769
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00340000000100000008003E00000034002C0030002C003200380034002C00, null, 0) WHERE diagram_id = @id -- index:72801
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0032003300310030002C00310032002C0032003700330030002C003100, null, 0) WHERE diagram_id = @id -- index:72833
    UPDATE sysdiagrams SET [definition] .Write ( 0x31002C0031003600380030000000520000005200000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:72865
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000000D002000006002800000041006300740069007600650054006100, null, 0) WHERE diagram_id = @id -- index:72897
    UPDATE sysdiagrams SET [definition] .Write ( 0x62006C00650056006900650077004D006F006400650000000100000008000400, null, 0) WHERE diagram_id = @id -- index:72929
    UPDATE sysdiagrams SET [definition] .Write ( 0x000031000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:72961
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00300000000100000008003A00000034002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:72993
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030002C0031002C0031003800390030002C00, null, 0) WHERE diagram_id = @id -- index:73025
    UPDATE sysdiagrams SET [definition] .Write ( 0x35002C0031003200360030000000200000005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:73057
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065003A00310000000100000008001E00000032002C00, null, 0) WHERE diagram_id = @id -- index:73089
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C003200380034002C0030002C0033003400380030000000200000005400, null, 0) WHERE diagram_id = @id -- index:73121
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00320000000100, null, 0) WHERE diagram_id = @id -- index:73153
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008001E00000032002C0030002C003200380034002C0030002C0032003300, null, 0) WHERE diagram_id = @id -- index:73185
    UPDATE sysdiagrams SET [definition] .Write ( 0x310030000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:73217
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00330000000100000008001E00000032002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:73249
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:73281
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00340000000100000008003E000000, null, 0) WHERE diagram_id = @id -- index:73313
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C003200380034002C0030002C0032003300310030002C003100, null, 0) WHERE diagram_id = @id -- index:73345
    UPDATE sysdiagrams SET [definition] .Write ( 0x32002C0032003700330030002C00310031002C00310036003800300000005300, null, 0) WHERE diagram_id = @id -- index:73377
    UPDATE sysdiagrams SET [definition] .Write ( 0x000053000000000000006000000001010C5F0100000073006E00610070007300, null, 0) WHERE diagram_id = @id -- index:73409
    UPDATE sysdiagrams SET [definition] .Write ( 0x68006F007400000046004B005F00500072006F006A0065006300740046006900, null, 0) WHERE diagram_id = @id -- index:73441
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650053006E0061007000730068006F0074005F00500072006F006A006500, null, 0) WHERE diagram_id = @id -- index:73473
    UPDATE sysdiagrams SET [definition] .Write ( 0x63007400460069006C00650000000000000000000000C4020000000054000000, null, 0) WHERE diagram_id = @id -- index:73505
    UPDATE sysdiagrams SET [definition] .Write ( 0x54000000530000000800000001B01D21D8B01D210000000000000000AD0F0000, null, 0) WHERE diagram_id = @id -- index:73537
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000055000000550000000000000060000000010000000100000073006E0061, null, 0) WHERE diagram_id = @id -- index:73569
    UPDATE sysdiagrams SET [definition] .Write ( 0x007000730068006F007400000046004B005F004C0069006E0065005000610074, null, 0) WHERE diagram_id = @id -- index:73601
    UPDATE sysdiagrams SET [definition] .Write ( 0x007400650072006E005F00500072006F006A00650063007400460069006C0065, null, 0) WHERE diagram_id = @id -- index:73633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0053006E0061007000730068006F00740000000000000000000000C402000000, null, 0) WHERE diagram_id = @id -- index:73665
    UPDATE sysdiagrams SET [definition] .Write ( 0x005600000056000000550000000800000001B51D2118B51D2100000000000000, null, 0) WHERE diagram_id = @id -- index:73697
    UPDATE sysdiagrams SET [definition] .Write ( 0x00AD0F00000100005700000057000000000000006C0000000104000001000000, null, 0) WHERE diagram_id = @id -- index:73729
    UPDATE sysdiagrams SET [definition] .Write ( 0x73006E0061007000730068006F007400000046004B005F0045006C0065006D00, null, 0) WHERE diagram_id = @id -- index:73761
    UPDATE sysdiagrams SET [definition] .Write ( 0x65006E00740044006500660069006E006900740069006F006E005F0050007200, null, 0) WHERE diagram_id = @id -- index:73793
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F006A00650063007400460069006C00650053006E0061007000730068006F00, null, 0) WHERE diagram_id = @id -- index:73825
    UPDATE sysdiagrams SET [definition] .Write ( 0x740000000000000000000000C402000000005800000058000000570000000800, null, 0) WHERE diagram_id = @id -- index:73857
    UPDATE sysdiagrams SET [definition] .Write ( 0x000001B41D2158B41D210000000000000000AD0F000001000059000000590000, null, 0) WHERE diagram_id = @id -- index:73889
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000000064000000010000410100000073006E0061007000730068006F0074, null, 0) WHERE diagram_id = @id -- index:73921
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000046004B005F00470072006F007500700049006E007300740061006E0063, null, 0) WHERE diagram_id = @id -- index:73953
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065005F00500072006F006A00650063007400460069006C00650053006E0061, null, 0) WHERE diagram_id = @id -- index:73985
    UPDATE sysdiagrams SET [definition] .Write ( 0x007000730068006F00740000000000000000000000C402000000005A0000005A, null, 0) WHERE diagram_id = @id -- index:74017
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000590000000800000001B11D2158B11D210000000000000000AD0F000001, null, 0) WHERE diagram_id = @id -- index:74049
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005B0000005B00000000000000000000000000000000000000D00200000600, null, 0) WHERE diagram_id = @id -- index:74081
    UPDATE sysdiagrams SET [definition] .Write ( 0x280000004100630074006900760065005400610062006C006500560069006500, null, 0) WHERE diagram_id = @id -- index:74113
    UPDATE sysdiagrams SET [definition] .Write ( 0x77004D006F006400650000000100000008000400000031000000200000005400, null, 0) WHERE diagram_id = @id -- index:74145
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00300000000100, null, 0) WHERE diagram_id = @id -- index:74177
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008003A00000034002C0030002C003200380034002C0030002C0032003300, null, 0) WHERE diagram_id = @id -- index:74209
    UPDATE sysdiagrams SET [definition] .Write ( 0x310030002C0031002C0031003800390030002C0035002C003100320036003000, null, 0) WHERE diagram_id = @id -- index:74241
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000200000005400610062006C00650056006900650077004D006F0064006500, null, 0) WHERE diagram_id = @id -- index:74273
    UPDATE sysdiagrams SET [definition] .Write ( 0x3A00310000000100000008001E00000032002C0030002C003200380034002C00, null, 0) WHERE diagram_id = @id -- index:74305
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0033003600360030000000200000005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:74337
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065003A00320000000100000008001E00000032002C00, null, 0) WHERE diagram_id = @id -- index:74369
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C003200380034002C0030002C0032003300310030000000200000005400, null, 0) WHERE diagram_id = @id -- index:74401
    UPDATE sysdiagrams SET [definition] .Write ( 0x610062006C00650056006900650077004D006F00640065003A00330000000100, null, 0) WHERE diagram_id = @id -- index:74433
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008001E00000032002C0030002C003200380034002C0030002C0032003300, null, 0) WHERE diagram_id = @id -- index:74465
    UPDATE sysdiagrams SET [definition] .Write ( 0x310030000000200000005400610062006C00650056006900650077004D006F00, null, 0) WHERE diagram_id = @id -- index:74497
    UPDATE sysdiagrams SET [definition] .Write ( 0x640065003A00340000000100000008003E00000034002C0030002C0032003800, null, 0) WHERE diagram_id = @id -- index:74529
    UPDATE sysdiagrams SET [definition] .Write ( 0x34002C0030002C0032003300310030002C00310032002C003200370033003000, null, 0) WHERE diagram_id = @id -- index:74561
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C00310031002C00310036003800300000005C0000005C000000000000007200, null, 0) WHERE diagram_id = @id -- index:74593
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000010000000100000073006E0061007000730068006F007400000046004B00, null, 0) WHERE diagram_id = @id -- index:74625
    UPDATE sysdiagrams SET [definition] .Write ( 0x5F00500072006F006A0065006300740049006E0066006F005000610072006100, null, 0) WHERE diagram_id = @id -- index:74657
    UPDATE sysdiagrams SET [definition] .Write ( 0x6D0065007400650072005F00500072006F006A00650063007400460069006C00, null, 0) WHERE diagram_id = @id -- index:74689
    UPDATE sysdiagrams SET [definition] .Write ( 0x650053006E0061007000730068006F00740000000000000000000000C4020000, null, 0) WHERE diagram_id = @id -- index:74721
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005D0000005D0000005C0000000800000001C11D2118C11D21000000000000, null, 0) WHERE diagram_id = @id -- index:74753
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000AD0F00000100005E0000005E000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:74785
    UPDATE sysdiagrams SET [definition] .Write ( 0x00D00200000600280000004100630074006900760065005400610062006C0065, null, 0) WHERE diagram_id = @id -- index:74817
    UPDATE sysdiagrams SET [definition] .Write ( 0x0056006900650077004D006F0064006500000001000000080004000000310000, null, 0) WHERE diagram_id = @id -- index:74849
    UPDATE sysdiagrams SET [definition] .Write ( 0x00200000005400610062006C00650056006900650077004D006F00640065003A, null, 0) WHERE diagram_id = @id -- index:74881
    UPDATE sysdiagrams SET [definition] .Write ( 0x00300000000100000008003A00000034002C0030002C003200380034002C0030, null, 0) WHERE diagram_id = @id -- index:74913
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0032003300310030002C0031002C0031003800390030002C0035002C0031, null, 0) WHERE diagram_id = @id -- index:74945
    UPDATE sysdiagrams SET [definition] .Write ( 0x003200360030000000200000005400610062006C00650056006900650077004D, null, 0) WHERE diagram_id = @id -- index:74977
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00640065003A00310000000100000008001E00000032002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:75009
    UPDATE sysdiagrams SET [definition] .Write ( 0x00380034002C0030002C0034003200330030000000200000005400610062006C, null, 0) WHERE diagram_id = @id -- index:75041
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650056006900650077004D006F00640065003A00320000000100000008001E, null, 0) WHERE diagram_id = @id -- index:75073
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000032002C0030002C003200380034002C0030002C00320033003100300000, null, 0) WHERE diagram_id = @id -- index:75105
    UPDATE sysdiagrams SET [definition] .Write ( 0x00200000005400610062006C00650056006900650077004D006F00640065003A, null, 0) WHERE diagram_id = @id -- index:75137
    UPDATE sysdiagrams SET [definition] .Write ( 0x00330000000100000008001E00000032002C0030002C003200380034002C0030, null, 0) WHERE diagram_id = @id -- index:75169
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0032003300310030000000200000005400610062006C0065005600690065, null, 0) WHERE diagram_id = @id -- index:75201
    UPDATE sysdiagrams SET [definition] .Write ( 0x0077004D006F00640065003A00340000000100000008003E00000034002C0030, null, 0) WHERE diagram_id = @id -- index:75233
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C003200380034002C0030002C0032003300310030002C00310032002C0032, null, 0) WHERE diagram_id = @id -- index:75265
    UPDATE sysdiagrams SET [definition] .Write ( 0x003700330030002C00310031002C00310036003800300000005F0000005F0000, null, 0) WHERE diagram_id = @id -- index:75297
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000D00200000600280000004100630074, null, 0) WHERE diagram_id = @id -- index:75329
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900760065005400610062006C00650056006900650077004D006F00640065, null, 0) WHERE diagram_id = @id -- index:75361
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000008000400000031000000200000005400610062006C00650056, null, 0) WHERE diagram_id = @id -- index:75393
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900650077004D006F00640065003A00300000000100000008003A00000034, null, 0) WHERE diagram_id = @id -- index:75425
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0030002C003200380034002C0030002C0032003300310030002C0031002C, null, 0) WHERE diagram_id = @id -- index:75457
    UPDATE sysdiagrams SET [definition] .Write ( 0x0031003800390030002C0035002C003100320036003000000020000000540061, null, 0) WHERE diagram_id = @id -- index:75489
    UPDATE sysdiagrams SET [definition] .Write ( 0x0062006C00650056006900650077004D006F00640065003A0031000000010000, null, 0) WHERE diagram_id = @id -- index:75521
    UPDATE sysdiagrams SET [definition] .Write ( 0x0008001E00000032002C0030002C003200380034002C0030002C003400330036, null, 0) WHERE diagram_id = @id -- index:75553
    UPDATE sysdiagrams SET [definition] .Write ( 0x0035000000200000005400610062006C00650056006900650077004D006F0064, null, 0) WHERE diagram_id = @id -- index:75585
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065003A00320000000100000008001E00000032002C0030002C003200380034, null, 0) WHERE diagram_id = @id -- index:75617
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0030002C0032003300310030000000200000005400610062006C00650056, null, 0) WHERE diagram_id = @id -- index:75649
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900650077004D006F00640065003A00330000000100000008001E00000032, null, 0) WHERE diagram_id = @id -- index:75681
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0030002C003200380034002C0030002C0032003300310030000000200000, null, 0) WHERE diagram_id = @id -- index:75713
    UPDATE sysdiagrams SET [definition] .Write ( 0x005400610062006C00650056006900650077004D006F00640065003A00340000, null, 0) WHERE diagram_id = @id -- index:75745
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100000008003E00000034002C0030002C003200380034002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:75777
    UPDATE sysdiagrams SET [definition] .Write ( 0x003300310030002C00310032002C0032003700330030002C00310031002C0031, null, 0) WHERE diagram_id = @id -- index:75809
    UPDATE sysdiagrams SET [definition] .Write ( 0x0036003800300000006000000060000000000000008A00000001010C5F010000, null, 0) WHERE diagram_id = @id -- index:75841
    UPDATE sysdiagrams SET [definition] .Write ( 0x0073006E0061007000730068006F007400000046004B005F00500072006F006A, null, 0) WHERE diagram_id = @id -- index:75873
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065006300740050006100720061006D00650074006500720043006100740065, null, 0) WHERE diagram_id = @id -- index:75905
    UPDATE sysdiagrams SET [definition] .Write ( 0x0067006F00720079005F00500072006F006A0065006300740050006100720061, null, 0) WHERE diagram_id = @id -- index:75937
    UPDATE sysdiagrams SET [definition] .Write ( 0x006D00650074006500720044006500660069006E006900740069006F006E0031, null, 0) WHERE diagram_id = @id -- index:75969
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000C40200000000610000006100000060000000080000, null, 0) WHERE diagram_id = @id -- index:76001
    UPDATE sysdiagrams SET [definition] .Write ( 0x00010E4817E00E48170000000000000000AD0F00000100006200000062000000, null, 0) WHERE diagram_id = @id -- index:76033
    UPDATE sysdiagrams SET [definition] .Write ( 0x000000007E000000013FBC580100000073006E0061007000730068006F007400, null, 0) WHERE diagram_id = @id -- index:76065
    UPDATE sysdiagrams SET [definition] .Write ( 0x000046004B005F00500072006F006A0065006300740050006100720061006D00, null, 0) WHERE diagram_id = @id -- index:76097
    UPDATE sysdiagrams SET [definition] .Write ( 0x650074006500720044006500660069006E006900740069006F006E005F005000, null, 0) WHERE diagram_id = @id -- index:76129
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006F006A00650063007400460069006C00650053006E006100700073006800, null, 0) WHERE diagram_id = @id -- index:76161
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00740000000000000000000000C40200000000630000006300000062000000, null, 0) WHERE diagram_id = @id -- index:76193
    UPDATE sysdiagrams SET [definition] .Write ( 0x0800000001519E2138519E210000000000000000AD0F00000100006400000064, null, 0) WHERE diagram_id = @id -- index:76225
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000000000000000000D0020000060028000000410063, null, 0) WHERE diagram_id = @id -- index:76257
    UPDATE sysdiagrams SET [definition] .Write ( 0x0074006900760065005400610062006C00650056006900650077004D006F0064, null, 0) WHERE diagram_id = @id -- index:76289
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650000000100000008000400000031000000200000005400610062006C0065, null, 0) WHERE diagram_id = @id -- index:76321
    UPDATE sysdiagrams SET [definition] .Write ( 0x0056006900650077004D006F00640065003A00300000000100000008003A0000, null, 0) WHERE diagram_id = @id -- index:76353
    UPDATE sysdiagrams SET [definition] .Write ( 0x0034002C0030002C003200380034002C0030002C0032003300310030002C0031, null, 0) WHERE diagram_id = @id -- index:76385
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0031003800390030002C0035002C00310032003600300000002000000054, null, 0) WHERE diagram_id = @id -- index:76417
    UPDATE sysdiagrams SET [definition] .Write ( 0x00610062006C00650056006900650077004D006F00640065003A003100000001, null, 0) WHERE diagram_id = @id -- index:76449
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000008001E00000032002C0030002C003200380034002C0030002C00320038, null, 0) WHERE diagram_id = @id -- index:76481
    UPDATE sysdiagrams SET [definition] .Write ( 0x00300035000000200000005400610062006C00650056006900650077004D006F, null, 0) WHERE diagram_id = @id -- index:76513
    UPDATE sysdiagrams SET [definition] .Write ( 0x00640065003A00320000000100000008001E00000032002C0030002C00320038, null, 0) WHERE diagram_id = @id -- index:76545
    UPDATE sysdiagrams SET [definition] .Write ( 0x0034002C0030002C0032003300310030000000200000005400610062006C0065, null, 0) WHERE diagram_id = @id -- index:76577
    UPDATE sysdiagrams SET [definition] .Write ( 0x0056006900650077004D006F00640065003A00330000000100000008001E0000, null, 0) WHERE diagram_id = @id -- index:76609
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032002C0030002C003200380034002C0030002C003200330031003000000020, null, 0) WHERE diagram_id = @id -- index:76641
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000005400610062006C00650056006900650077004D006F00640065003A0034, null, 0) WHERE diagram_id = @id -- index:76673
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000008003E00000034002C0030002C003200380034002C0030002C, null, 0) WHERE diagram_id = @id -- index:76705
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032003300310030002C00310032002C0032003700330030002C00310031002C, null, 0) WHERE diagram_id = @id -- index:76737
    UPDATE sysdiagrams SET [definition] .Write ( 0x0031003600380030000000650000006500000000000000420000000100000001, null, 0) WHERE diagram_id = @id -- index:76769
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000061007300730065007400000046004B005F00500072006F006A00650063, null, 0) WHERE diagram_id = @id -- index:76801
    UPDATE sysdiagrams SET [definition] .Write ( 0x00740050006100740068005F00500072006F006A006500630074000000000000, null, 0) WHERE diagram_id = @id -- index:76833
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000C402000000006600000066000000650000000800000001559E2138, null, 0) WHERE diagram_id = @id -- index:76865
    UPDATE sysdiagrams SET [definition] .Write ( 0x559E210000000000000000AD0F00000100006700000067000000000000000000, null, 0) WHERE diagram_id = @id -- index:76897
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000D0020000060028000000410063007400690076006500, null, 0) WHERE diagram_id = @id -- index:76929
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F0064006500000001000000, null, 0) WHERE diagram_id = @id -- index:76961
    UPDATE sysdiagrams SET [definition] .Write ( 0x08000400000031000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:76993
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00300000000100000008003A00000034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:77025
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C0032003300310030002C0031002C00310038003900, null, 0) WHERE diagram_id = @id -- index:77057
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0035002C0031003200360030000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:77089
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00310000000100000008001E000000, null, 0) WHERE diagram_id = @id -- index:77121
    UPDATE sysdiagrams SET [definition] .Write ( 0x32002C0030002C003200380034002C0030002C00330034003000350000002000, null, 0) WHERE diagram_id = @id -- index:77153
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005400610062006C00650056006900650077004D006F00640065003A003200, null, 0) WHERE diagram_id = @id -- index:77185
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000008001E00000032002C0030002C003200380034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:77217
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003300310030000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:77249
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00330000000100000008001E00000032002C0030002C00, null, 0) WHERE diagram_id = @id -- index:77281
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C003200330031003000000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:77313
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0034000000010000000800, null, 0) WHERE diagram_id = @id -- index:77345
    UPDATE sysdiagrams SET [definition] .Write ( 0x3E00000034002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:77377
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C00310032002C0032003700330030002C00310031002C003100360038003000, null, 0) WHERE diagram_id = @id -- index:77409
    UPDATE sysdiagrams SET [definition] .Write ( 0x00006800000068000000000000006E000000010300000100000073006E006100, null, 0) WHERE diagram_id = @id -- index:77441
    UPDATE sysdiagrams SET [definition] .Write ( 0x7000730068006F007400000046004B005F00500072006F006A00650063007400, null, 0) WHERE diagram_id = @id -- index:77473
    UPDATE sysdiagrams SET [definition] .Write ( 0x55006E0075007300650064004900740065006D0073005F00500072006F006A00, null, 0) WHERE diagram_id = @id -- index:77505
    UPDATE sysdiagrams SET [definition] .Write ( 0x650063007400460069006C00650053006E0061007000730068006F0074000000, null, 0) WHERE diagram_id = @id -- index:77537
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000C40200000000690000006900000068000000080000000156, null, 0) WHERE diagram_id = @id -- index:77569
    UPDATE sysdiagrams SET [definition] .Write ( 0x9E2138569E210000000000000000AD0F00000100006A0000006A000000000000, null, 0) WHERE diagram_id = @id -- index:77601
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000000000D0020000060028000000410063007400690076, null, 0) WHERE diagram_id = @id -- index:77633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065005400610062006C00650056006900650077004D006F0064006500000001, null, 0) WHERE diagram_id = @id -- index:77665
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000008000400000031000000200000005400610062006C0065005600690065, null, 0) WHERE diagram_id = @id -- index:77697
    UPDATE sysdiagrams SET [definition] .Write ( 0x0077004D006F00640065003A00300000000100000008003A00000034002C0030, null, 0) WHERE diagram_id = @id -- index:77729
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C003200380034002C0030002C0032003300310030002C0031002C00310038, null, 0) WHERE diagram_id = @id -- index:77761
    UPDATE sysdiagrams SET [definition] .Write ( 0x00390030002C0035002C0031003200360030000000200000005400610062006C, null, 0) WHERE diagram_id = @id -- index:77793
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650056006900650077004D006F00640065003A00310000000100000008001E, null, 0) WHERE diagram_id = @id -- index:77825
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000032002C0030002C003200380034002C0030002C00320038003000350000, null, 0) WHERE diagram_id = @id -- index:77857
    UPDATE sysdiagrams SET [definition] .Write ( 0x00200000005400610062006C00650056006900650077004D006F00640065003A, null, 0) WHERE diagram_id = @id -- index:77889
    UPDATE sysdiagrams SET [definition] .Write ( 0x00320000000100000008001E00000032002C0030002C003200380034002C0030, null, 0) WHERE diagram_id = @id -- index:77921
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0032003300310030000000200000005400610062006C0065005600690065, null, 0) WHERE diagram_id = @id -- index:77953
    UPDATE sysdiagrams SET [definition] .Write ( 0x0077004D006F00640065003A00330000000100000008001E00000032002C0030, null, 0) WHERE diagram_id = @id -- index:77985
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C003200380034002C0030002C003200330031003000000020000000540061, null, 0) WHERE diagram_id = @id -- index:78017
    UPDATE sysdiagrams SET [definition] .Write ( 0x0062006C00650056006900650077004D006F00640065003A0034000000010000, null, 0) WHERE diagram_id = @id -- index:78049
    UPDATE sysdiagrams SET [definition] .Write ( 0x0008003E00000034002C0030002C003200380034002C0030002C003200330031, null, 0) WHERE diagram_id = @id -- index:78081
    UPDATE sysdiagrams SET [definition] .Write ( 0x0030002C00310032002C0032003700330030002C00310031002C003100360038, null, 0) WHERE diagram_id = @id -- index:78113
    UPDATE sysdiagrams SET [definition] .Write ( 0x00300000006B0000006B000000000000005A000000013FBC580100000073006E, null, 0) WHERE diagram_id = @id -- index:78145
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061007000730068006F007400000046004B005F005300630068006500640075, null, 0) WHERE diagram_id = @id -- index:78177
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C0065005F00500072006F006A00650063007400460069006C00650053006E, null, 0) WHERE diagram_id = @id -- index:78209
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061007000730068006F00740000000000000000000000C402000000006C0000, null, 0) WHERE diagram_id = @id -- index:78241
    UPDATE sysdiagrams SET [definition] .Write ( 0x006C0000006B00000008000000014F9E21F84F9E210000000000000000AD0F00, null, 0) WHERE diagram_id = @id -- index:78273
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100006D0000006D00000000000000000000000000000000000000D0020000, null, 0) WHERE diagram_id = @id -- index:78305
    UPDATE sysdiagrams SET [definition] .Write ( 0x0600280000004100630074006900760065005400610062006C00650056006900, null, 0) WHERE diagram_id = @id -- index:78337
    UPDATE sysdiagrams SET [definition] .Write ( 0x650077004D006F00640065000000010000000800040000003100000020000000, null, 0) WHERE diagram_id = @id -- index:78369
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F00640065003A0030000000, null, 0) WHERE diagram_id = @id -- index:78401
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000008003A00000034002C0030002C003200380034002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:78433
    UPDATE sysdiagrams SET [definition] .Write ( 0x3300310030002C0031002C0031003800390030002C0035002C00310032003600, null, 0) WHERE diagram_id = @id -- index:78465
    UPDATE sysdiagrams SET [definition] .Write ( 0x30000000200000005400610062006C00650056006900650077004D006F006400, null, 0) WHERE diagram_id = @id -- index:78497
    UPDATE sysdiagrams SET [definition] .Write ( 0x65003A00310000000100000008001E00000032002C0030002C00320038003400, null, 0) WHERE diagram_id = @id -- index:78529
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0030002C0032003800300035000000200000005400610062006C0065005600, null, 0) WHERE diagram_id = @id -- index:78561
    UPDATE sysdiagrams SET [definition] .Write ( 0x6900650077004D006F00640065003A00320000000100000008001E0000003200, null, 0) WHERE diagram_id = @id -- index:78593
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C0030002C003200380034002C0030002C003200330031003000000020000000, null, 0) WHERE diagram_id = @id -- index:78625
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F00640065003A0033000000, null, 0) WHERE diagram_id = @id -- index:78657
    UPDATE sysdiagrams SET [definition] .Write ( 0x0100000008001E00000032002C0030002C003200380034002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:78689
    UPDATE sysdiagrams SET [definition] .Write ( 0x3300310030000000200000005400610062006C00650056006900650077004D00, null, 0) WHERE diagram_id = @id -- index:78721
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00640065003A00340000000100000008003E00000034002C0030002C003200, null, 0) WHERE diagram_id = @id -- index:78753
    UPDATE sysdiagrams SET [definition] .Write ( 0x380034002C0030002C0032003300310030002C00310032002C00320037003300, null, 0) WHERE diagram_id = @id -- index:78785
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C00310031002C00310036003800300000006E0000006E00000000000000, null, 0) WHERE diagram_id = @id -- index:78817
    UPDATE sysdiagrams SET [definition] .Write ( 0x50000000013FBC580100000073006E0061007000730068006F00740000004600, null, 0) WHERE diagram_id = @id -- index:78849
    UPDATE sysdiagrams SET [definition] .Write ( 0x4B005F005300630068006500640075006C0065004600690065006C0064005F00, null, 0) WHERE diagram_id = @id -- index:78881
    UPDATE sysdiagrams SET [definition] .Write ( 0x5300630068006500640075006C006500310000000000000000000000C4020000, null, 0) WHERE diagram_id = @id -- index:78913
    UPDATE sysdiagrams SET [definition] .Write ( 0x00006F0000006F0000006E0000000800000001509E21F8509E21000000000000, null, 0) WHERE diagram_id = @id -- index:78945
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000AD0F00000100007000000070000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:78977
    UPDATE sysdiagrams SET [definition] .Write ( 0x00D00200000600280000004100630074006900760065005400610062006C0065, null, 0) WHERE diagram_id = @id -- index:79009
    UPDATE sysdiagrams SET [definition] .Write ( 0x0056006900650077004D006F0064006500000001000000080004000000310000, null, 0) WHERE diagram_id = @id -- index:79041
    UPDATE sysdiagrams SET [definition] .Write ( 0x00200000005400610062006C00650056006900650077004D006F00640065003A, null, 0) WHERE diagram_id = @id -- index:79073
    UPDATE sysdiagrams SET [definition] .Write ( 0x00300000000100000008003A00000034002C0030002C003200380034002C0030, null, 0) WHERE diagram_id = @id -- index:79105
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0032003300310030002C0031002C0031003800390030002C0035002C0031, null, 0) WHERE diagram_id = @id -- index:79137
    UPDATE sysdiagrams SET [definition] .Write ( 0x003200360030000000200000005400610062006C00650056006900650077004D, null, 0) WHERE diagram_id = @id -- index:79169
    UPDATE sysdiagrams SET [definition] .Write ( 0x006F00640065003A00310000000100000008001E00000032002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:79201
    UPDATE sysdiagrams SET [definition] .Write ( 0x00380034002C0030002C0032003800300035000000200000005400610062006C, null, 0) WHERE diagram_id = @id -- index:79233
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650056006900650077004D006F00640065003A00320000000100000008001E, null, 0) WHERE diagram_id = @id -- index:79265
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000032002C0030002C003200380034002C0030002C00320033003100300000, null, 0) WHERE diagram_id = @id -- index:79297
    UPDATE sysdiagrams SET [definition] .Write ( 0x00200000005400610062006C00650056006900650077004D006F00640065003A, null, 0) WHERE diagram_id = @id -- index:79329
    UPDATE sysdiagrams SET [definition] .Write ( 0x00330000000100000008001E00000032002C0030002C003200380034002C0030, null, 0) WHERE diagram_id = @id -- index:79361
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0032003300310030000000200000005400610062006C0065005600690065, null, 0) WHERE diagram_id = @id -- index:79393
    UPDATE sysdiagrams SET [definition] .Write ( 0x0077004D006F00640065003A00340000000100000008003E00000034002C0030, null, 0) WHERE diagram_id = @id -- index:79425
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C003200380034002C0030002C0032003300310030002C00310032002C0032, null, 0) WHERE diagram_id = @id -- index:79457
    UPDATE sysdiagrams SET [definition] .Write ( 0x003700330030002C00310031002C003100360038003000000071000000710000, null, 0) WHERE diagram_id = @id -- index:79489
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000D00200000600280000004100630074, null, 0) WHERE diagram_id = @id -- index:79521
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900760065005400610062006C00650056006900650077004D006F00640065, null, 0) WHERE diagram_id = @id -- index:79553
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000100000008000400000031000000200000005400610062006C00650056, null, 0) WHERE diagram_id = @id -- index:79585
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900650077004D006F00640065003A00300000000100000008003A00000034, null, 0) WHERE diagram_id = @id -- index:79617
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0030002C003200380034002C0030002C0032003300310030002C0031002C, null, 0) WHERE diagram_id = @id -- index:79649
    UPDATE sysdiagrams SET [definition] .Write ( 0x0031003800390030002C0035002C003100320036003000000020000000540061, null, 0) WHERE diagram_id = @id -- index:79681
    UPDATE sysdiagrams SET [definition] .Write ( 0x0062006C00650056006900650077004D006F00640065003A0031000000010000, null, 0) WHERE diagram_id = @id -- index:79713
    UPDATE sysdiagrams SET [definition] .Write ( 0x0008001E00000032002C0030002C003200380034002C0030002C003200380030, null, 0) WHERE diagram_id = @id -- index:79745
    UPDATE sysdiagrams SET [definition] .Write ( 0x0035000000200000005400610062006C00650056006900650077004D006F0064, null, 0) WHERE diagram_id = @id -- index:79777
    UPDATE sysdiagrams SET [definition] .Write ( 0x0065003A00320000000100000008001E00000032002C0030002C003200380034, null, 0) WHERE diagram_id = @id -- index:79809
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0030002C0032003300310030000000200000005400610062006C00650056, null, 0) WHERE diagram_id = @id -- index:79841
    UPDATE sysdiagrams SET [definition] .Write ( 0x006900650077004D006F00640065003A00330000000100000008001E00000032, null, 0) WHERE diagram_id = @id -- index:79873
    UPDATE sysdiagrams SET [definition] .Write ( 0x002C0030002C003200380034002C0030002C0032003300310030000000200000, null, 0) WHERE diagram_id = @id -- index:79905
    UPDATE sysdiagrams SET [definition] .Write ( 0x005400610062006C00650056006900650077004D006F00640065003A00340000, null, 0) WHERE diagram_id = @id -- index:79937
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100000008003E00000034002C0030002C003200380034002C0030002C0032, null, 0) WHERE diagram_id = @id -- index:79969
    UPDATE sysdiagrams SET [definition] .Write ( 0x003300310030002C00310032002C0032003700330030002C00310031002C0031, null, 0) WHERE diagram_id = @id -- index:80001
    UPDATE sysdiagrams SET [definition] .Write ( 0x00360038003000000072000000720000000000000050000000013FBC58010000, null, 0) WHERE diagram_id = @id -- index:80033
    UPDATE sysdiagrams SET [definition] .Write ( 0x0073006E0061007000730068006F007400000046004B005F005700610072006E, null, 0) WHERE diagram_id = @id -- index:80065
    UPDATE sysdiagrams SET [definition] .Write ( 0x0069006E0067005F0045006C0065006D0065006E00740049006E007300740061, null, 0) WHERE diagram_id = @id -- index:80097
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E006300650000000000000000000000C40200000000730000007300000072, null, 0) WHERE diagram_id = @id -- index:80129
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000800000001539E21B8539E210000000000000000AD0F00000100007400, null, 0) WHERE diagram_id = @id -- index:80161
    UPDATE sysdiagrams SET [definition] .Write ( 0x000074000000000000005200000001AB8A680100000073006E00610070007300, null, 0) WHERE diagram_id = @id -- index:80193
    UPDATE sysdiagrams SET [definition] .Write ( 0x68006F007400000046004B005F005700610072006E0069006E0067005F004500, null, 0) WHERE diagram_id = @id -- index:80225
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C0065006D0065006E00740049006E007300740061006E006300650031000000, null, 0) WHERE diagram_id = @id -- index:80257
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000C40200000000750000007500000074000000080000000157, null, 0) WHERE diagram_id = @id -- index:80289
    UPDATE sysdiagrams SET [definition] .Write ( 0x9E2178579E210000000000000000AD0F00000100007600000076000000000000, null, 0) WHERE diagram_id = @id -- index:80321
    UPDATE sysdiagrams SET [definition] .Write ( 0x005800000001AB8A680100000073006E0061007000730068006F007400000046, null, 0) WHERE diagram_id = @id -- index:80353
    UPDATE sysdiagrams SET [definition] .Write ( 0x004B005F005700610072006E0069006E0067005F00500072006F006A00650063, null, 0) WHERE diagram_id = @id -- index:80385
    UPDATE sysdiagrams SET [definition] .Write ( 0x007400460069006C00650053006E0061007000730068006F0074000000000000, null, 0) WHERE diagram_id = @id -- index:80417
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000C4020000000077000000770000007600000008000000015E9E21F8, null, 0) WHERE diagram_id = @id -- index:80449
    UPDATE sysdiagrams SET [definition] .Write ( 0x5E9E210000000000000000AD0F00000100007800000078000000000000000000, null, 0) WHERE diagram_id = @id -- index:80481
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000000000000000000D0020000060028000000410063007400690076006500, null, 0) WHERE diagram_id = @id -- index:80513
    UPDATE sysdiagrams SET [definition] .Write ( 0x5400610062006C00650056006900650077004D006F0064006500000001000000, null, 0) WHERE diagram_id = @id -- index:80545
    UPDATE sysdiagrams SET [definition] .Write ( 0x08000400000031000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:80577
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00300000000100000008003A00000034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:80609
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C0032003300310030002C0031002C00310038003900, null, 0) WHERE diagram_id = @id -- index:80641
    UPDATE sysdiagrams SET [definition] .Write ( 0x30002C0035002C0031003200360030000000200000005400610062006C006500, null, 0) WHERE diagram_id = @id -- index:80673
    UPDATE sysdiagrams SET [definition] .Write ( 0x56006900650077004D006F00640065003A00310000000100000008001E000000, null, 0) WHERE diagram_id = @id -- index:80705
    UPDATE sysdiagrams SET [definition] .Write ( 0x32002C0030002C003200380034002C0030002C00320038003000350000002000, null, 0) WHERE diagram_id = @id -- index:80737
    UPDATE sysdiagrams SET [definition] .Write ( 0x00005400610062006C00650056006900650077004D006F00640065003A003200, null, 0) WHERE diagram_id = @id -- index:80769
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000100000008001E00000032002C0030002C003200380034002C0030002C00, null, 0) WHERE diagram_id = @id -- index:80801
    UPDATE sysdiagrams SET [definition] .Write ( 0x32003300310030000000200000005400610062006C0065005600690065007700, null, 0) WHERE diagram_id = @id -- index:80833
    UPDATE sysdiagrams SET [definition] .Write ( 0x4D006F00640065003A00330000000100000008001E00000032002C0030002C00, null, 0) WHERE diagram_id = @id -- index:80865
    UPDATE sysdiagrams SET [definition] .Write ( 0x3200380034002C0030002C003200330031003000000020000000540061006200, null, 0) WHERE diagram_id = @id -- index:80897
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650056006900650077004D006F00640065003A0034000000010000000800, null, 0) WHERE diagram_id = @id -- index:80929
    UPDATE sysdiagrams SET [definition] .Write ( 0x3E00000034002C0030002C003200380034002C0030002C003200330031003000, null, 0) WHERE diagram_id = @id -- index:80961
    UPDATE sysdiagrams SET [definition] .Write ( 0x2C00310032002C0032003700330030002C00310031002C003100360038003000, null, 0) WHERE diagram_id = @id -- index:80993
    UPDATE sysdiagrams SET [definition] .Write ( 0x000079000000790000000000000040000000010000000100000073006E006100, null, 0) WHERE diagram_id = @id -- index:81025
    UPDATE sysdiagrams SET [definition] .Write ( 0x7000730068006F007400000046004B005F005700610072006E0069006E006700, null, 0) WHERE diagram_id = @id -- index:81057
    UPDATE sysdiagrams SET [definition] .Write ( 0x5F0057006F0072006B0073006500740000000000000000000000C40200000000, null, 0) WHERE diagram_id = @id -- index:81089
    UPDATE sysdiagrams SET [definition] .Write ( 0x7A0000007A0000007900000008000000015B9E21385B9E210000000000000000, null, 0) WHERE diagram_id = @id -- index:81121
    UPDATE sysdiagrams SET [definition] .Write ( 0xAD0F00000100007B0000007B000000000000005800000001AB8A680100000073, null, 0) WHERE diagram_id = @id -- index:81153
    UPDATE sysdiagrams SET [definition] .Write ( 0x006E0061007000730068006F007400000046004B005F0057006F0072006B0073, null, 0) WHERE diagram_id = @id -- index:81185
    UPDATE sysdiagrams SET [definition] .Write ( 0x00650074005F00500072006F006A00650063007400460069006C00650053006E, null, 0) WHERE diagram_id = @id -- index:81217
    UPDATE sysdiagrams SET [definition] .Write ( 0x0061007000730068006F00740000000000000000000000C402000000007C0000, null, 0) WHERE diagram_id = @id -- index:81249
    UPDATE sysdiagrams SET [definition] .Write ( 0x007C0000007B0000000800000001599E21B8599E210000000000000000AD0F00, null, 0) WHERE diagram_id = @id -- index:81281
    UPDATE sysdiagrams SET [definition] .Write ( 0x000100007D0000007D0000000000000050000000013FBC580100000073006E00, null, 0) WHERE diagram_id = @id -- index:81313
    UPDATE sysdiagrams SET [definition] .Write ( 0x61007000730068006F007400000046004B005F0045006C0065006D0065006E00, null, 0) WHERE diagram_id = @id -- index:81345
    UPDATE sysdiagrams SET [definition] .Write ( 0x740049006E007300740061006E00630065005F0057006F0072006B0073006500, null, 0) WHERE diagram_id = @id -- index:81377
    UPDATE sysdiagrams SET [definition] .Write ( 0x740000000000000000000000C402000000007E0000007E0000007D0000000800, null, 0) WHERE diagram_id = @id -- index:81409
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000015D9E21B85D9E210000000000000000AD0F0000010000D7000000110000, null, 0) WHERE diagram_id = @id -- index:81441
    UPDATE sysdiagrams SET [definition] .Write ( 0x0002000000100000009E000000790000000C000000020000000B000000980000, null, 0) WHERE diagram_id = @id -- index:81473
    UPDATE sysdiagrams SET [definition] .Write ( 0x00F50000000600000002000000050000002A0000002B00000003000000020000, null, 0) WHERE diagram_id = @id -- index:81505
    UPDATE sysdiagrams SET [definition] .Write ( 0x00010000009D0000005C000000740000000500000071000000C3000000840000, null, 0) WHERE diagram_id = @id -- index:81537
    UPDATE sysdiagrams SET [definition] .Write ( 0x00720000000500000071000000BD0000007E00000020000000050000001F0000, null, 0) WHERE diagram_id = @id -- index:81569
    UPDATE sysdiagrams SET [definition] .Write ( 0x00B60000009F0000001D000000050000001A000000C2000000990000001B0000, null, 0) WHERE diagram_id = @id -- index:81601
    UPDATE sysdiagrams SET [definition] .Write ( 0x00050000001A000000BC000000930000000E000000050000000B000000250000, null, 0) WHERE diagram_id = @id -- index:81633
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032000000090000000500000008000000310000004200000018000000100000, null, 0) WHERE diagram_id = @id -- index:81665
    UPDATE sysdiagrams SET [definition] .Write ( 0x0017000000250000003C000000150000001000000005000000240000001F0000, null, 0) WHERE diagram_id = @id -- index:81697
    UPDATE sysdiagrams SET [definition] .Write ( 0x0013000000100000000B00000073000000F4000000250000001A000000240000, null, 0) WHERE diagram_id = @id -- index:81729
    UPDATE sysdiagrams SET [definition] .Write ( 0x002200000029000000220000001A0000001F00000028000000470000004E0000, null, 0) WHERE diagram_id = @id -- index:81761
    UPDATE sysdiagrams SET [definition] .Write ( 0x002A0000004D0000001F000000280000004B0000002A0000004A0000001F0100, null, 0) WHERE diagram_id = @id -- index:81793
    UPDATE sysdiagrams SET [definition] .Write ( 0x007A000000480000002A000000470000002400000025000000450000002A0000, null, 0) WHERE diagram_id = @id -- index:81825
    UPDATE sysdiagrams SET [definition] .Write ( 0x00440000002B00000024000000400000002A0000003F000000240100007B0000, null, 0) WHERE diagram_id = @id -- index:81857
    UPDATE sysdiagrams SET [definition] .Write ( 0x003D0000002A0000003C0000002A000000250000003A0000002A000000390000, null, 0) WHERE diagram_id = @id -- index:81889
    UPDATE sysdiagrams SET [definition] .Write ( 0x002501000072000000370000002A000000360000001E010000A1000000330000, null, 0) WHERE diagram_id = @id -- index:81921
    UPDATE sysdiagrams SET [definition] .Write ( 0x002A000000320000002500000024000000300000002A0000002F000000190100, null, 0) WHERE diagram_id = @id -- index:81953
    UPDATE sysdiagrams SET [definition] .Write ( 0x007E0000002D0000002A00000029000000180100007B0000002B0000002A0000, null, 0) WHERE diagram_id = @id -- index:81985
    UPDATE sysdiagrams SET [definition] .Write ( 0x00280000001E000000250000006500000050000000640000000C000000250000, null, 0) WHERE diagram_id = @id -- index:82017
    UPDATE sysdiagrams SET [definition] .Write ( 0x0053000000510000005200000025000000380000007B00000052000000780000, null, 0) WHERE diagram_id = @id -- index:82049
    UPDATE sysdiagrams SET [definition] .Write ( 0x0032000000250000007600000052000000710000002C000000250000006B0000, null, 0) WHERE diagram_id = @id -- index:82081
    UPDATE sysdiagrams SET [definition] .Write ( 0x00520000006A000000FD01000090000000680000005200000067000000030200, null, 0) WHERE diagram_id = @id -- index:82113
    UPDATE sysdiagrams SET [definition] .Write ( 0x007800000062000000520000005F00000029000000360000005C000000520000, null, 0) WHERE diagram_id = @id -- index:82145
    UPDATE sysdiagrams SET [definition] .Write ( 0x005B0000002F0000002E00000059000000520000001A00000020000000270000, null, 0) WHERE diagram_id = @id -- index:82177
    UPDATE sysdiagrams SET [definition] .Write ( 0x00570000005200000002000000260000002B0000005500000052000000270000, null, 0) WHERE diagram_id = @id -- index:82209
    UPDATE sysdiagrams SET [definition] .Write ( 0x00FE01000061000000600000005F0000005E00000037000000340000006E0000, null, 0) WHERE diagram_id = @id -- index:82241
    UPDATE sysdiagrams SET [definition] .Write ( 0x006A0000006D00000025000000240000007D0000007800000005000000760000, null, 0) WHERE diagram_id = @id -- index:82273
    UPDATE sysdiagrams SET [definition] .Write ( 0x00B70000007900000078000000710000007C0000008300000000000000000000, null, 0) WHERE diagram_id = @id -- index:82305
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:82337
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:82369
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:82401
    UPDATE sysdiagrams SET [definition] .Write ( 0x7400530065007200760065007200430065007200740069006600690063006100, null, 0) WHERE diagram_id = @id -- index:82433
    UPDATE sysdiagrams SET [definition] .Write ( 0x740065003D00460061006C00730065003B005000610063006B00650074002000, null, 0) WHERE diagram_id = @id -- index:82465
    UPDATE sysdiagrams SET [definition] .Write ( 0x530069007A0065003D0034003000390036003B004100700070006C0069006300, null, 0) WHERE diagram_id = @id -- index:82497
    UPDATE sysdiagrams SET [definition] .Write ( 0x6100740069006F006E0020004E0061006D0065003D0022004D00690063007200, null, 0) WHERE diagram_id = @id -- index:82529
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F0073006F00660074002000530051004C002000530065007200760065007200, null, 0) WHERE diagram_id = @id -- index:82561
    UPDATE sysdiagrams SET [definition] .Write ( 0x20004D0061006E006100670065006D0065006E00740020005300740075006400, null, 0) WHERE diagram_id = @id -- index:82593
    UPDATE sysdiagrams SET [definition] .Write ( 0x69006F002200000000800500160000004400690061006C006F0067005F004100, null, 0) WHERE diagram_id = @id -- index:82625
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C006C00000000022600160000004400690073006300690070006C0069006E00, null, 0) WHERE diagram_id = @id -- index:82657
    UPDATE sysdiagrams SET [definition] .Write ( 0x650000001200000073006E0061007000730068006F0074000000000226002400, null, 0) WHERE diagram_id = @id -- index:82689
    UPDATE sysdiagrams SET [definition] .Write ( 0x000045006C0065006D0065006E00740044006500660069006E00690074006900, null, 0) WHERE diagram_id = @id -- index:82721
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F006E0000001200000073006E0061007000730068006F007400000000022600, null, 0) WHERE diagram_id = @id -- index:82753
    UPDATE sysdiagrams SET [definition] .Write ( 0x2000000045006C0065006D0065006E00740049006E007300740061006E006300, null, 0) WHERE diagram_id = @id -- index:82785
    UPDATE sysdiagrams SET [definition] .Write ( 0x650000001200000073006E0061007000730068006F0074000000000226004000, null, 0) WHERE diagram_id = @id -- index:82817
    UPDATE sysdiagrams SET [definition] .Write ( 0x000045006C0065006D0065006E00740049006E007300740061006E0063006500, null, 0) WHERE diagram_id = @id -- index:82849
    UPDATE sysdiagrams SET [definition] .Write ( 0x440069006D0065006E00730069006F006E005300650067006D0065006E007400, null, 0) WHERE diagram_id = @id -- index:82881
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001200000073006E0061007000730068006F0074000000000226002C000000, null, 0) WHERE diagram_id = @id -- index:82913
    UPDATE sysdiagrams SET [definition] .Write ( 0x45006C0065006D0065006E00740050006100720061006D006500740065007200, null, 0) WHERE diagram_id = @id -- index:82945
    UPDATE sysdiagrams SET [definition] .Write ( 0x560061006C007500650000001200000073006E0061007000730068006F007400, null, 0) WHERE diagram_id = @id -- index:82977
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000226001800000045006C0065006D0065006E0074005400790070006500, null, 0) WHERE diagram_id = @id -- index:83009
    UPDATE sysdiagrams SET [definition] .Write ( 0x00001200000073006E0061007000730068006F0074000000000226003A000000, null, 0) WHERE diagram_id = @id -- index:83041
    UPDATE sysdiagrams SET [definition] .Write ( 0x45006C0065006D0065006E007400540079007000650043006F006E0073007400, null, 0) WHERE diagram_id = @id -- index:83073
    UPDATE sysdiagrams SET [definition] .Write ( 0x720075006300740069006F006E004C0061007900650072000000120000007300, null, 0) WHERE diagram_id = @id -- index:83105
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0061007000730068006F0074000000000226001C000000470072006F007500, null, 0) WHERE diagram_id = @id -- index:83137
    UPDATE sysdiagrams SET [definition] .Write ( 0x700049006E007300740061006E006300650000001200000073006E0061007000, null, 0) WHERE diagram_id = @id -- index:83169
    UPDATE sysdiagrams SET [definition] .Write ( 0x730068006F00740000000002260046000000470072006F007500700049006E00, null, 0) WHERE diagram_id = @id -- index:83201
    UPDATE sysdiagrams SET [definition] .Write ( 0x7300740061006E006300650045006C0065006D0065006E00740049006E007300, null, 0) WHERE diagram_id = @id -- index:83233
    UPDATE sysdiagrams SET [definition] .Write ( 0x740061006E00630065004C006F006F006B007500700000001200000073006E00, null, 0) WHERE diagram_id = @id -- index:83265
    UPDATE sysdiagrams SET [definition] .Write ( 0x61007000730068006F00740000000002260038000000470072006F0075007000, null, 0) WHERE diagram_id = @id -- index:83297
    UPDATE sysdiagrams SET [definition] .Write ( 0x49006E007300740061006E006300650050006100720061006D00650074006500, null, 0) WHERE diagram_id = @id -- index:83329
    UPDATE sysdiagrams SET [definition] .Write ( 0x7200560061006C007500650000001200000073006E0061007000730068006F00, null, 0) WHERE diagram_id = @id -- index:83361
    UPDATE sysdiagrams SET [definition] .Write ( 0x7400000000022600180000004C0069006E006500500061007400740065007200, null, 0) WHERE diagram_id = @id -- index:83393
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0000001200000073006E0061007000730068006F0074000000000226001200, null, 0) WHERE diagram_id = @id -- index:83425
    UPDATE sysdiagrams SET [definition] .Write ( 0x00004C006F00670041006400640049006E00000008000000700061006C000000, null, 0) WHERE diagram_id = @id -- index:83457
    UPDATE sysdiagrams SET [definition] .Write ( 0x00022600120000004C006F006700430072006100730068000000080000007000, null, 0) WHERE diagram_id = @id -- index:83489
    UPDATE sysdiagrams SET [definition] .Write ( 0x61006C000000000226001C0000004C006F00670044006F006300530065007300, null, 0) WHERE diagram_id = @id -- index:83521
    UPDATE sysdiagrams SET [definition] .Write ( 0x730069006F006E00000008000000700061006C000000000226002C0000004C00, null, 0) WHERE diagram_id = @id -- index:83553
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00670044006F00630075006D0065006E007400500072006F006A0043006800, null, 0) WHERE diagram_id = @id -- index:83585
    UPDATE sysdiagrams SET [definition] .Write ( 0x61006E0067006500000008000000700061006C00000000022600160000004C00, null, 0) WHERE diagram_id = @id -- index:83617
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00670045006C0065006D0065006E007400000008000000700061006C000000, null, 0) WHERE diagram_id = @id -- index:83649
    UPDATE sysdiagrams SET [definition] .Write ( 0x00022600100000004C006F00670045004E0055004D0000000800000070006100, null, 0) WHERE diagram_id = @id -- index:83681
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00000000022600120000004C006F0067004500760065006E00740000000800, null, 0) WHERE diagram_id = @id -- index:83713
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000700061006C00000000022600100000004C006F0067004C0069006E006B00, null, 0) WHERE diagram_id = @id -- index:83745
    UPDATE sysdiagrams SET [definition] .Write ( 0x000008000000700061006C00000000022600160000004C006F0067004D006100, null, 0) WHERE diagram_id = @id -- index:83777
    UPDATE sysdiagrams SET [definition] .Write ( 0x6300680069006E006500000008000000700061006C0000000002260012000000, null, 0) WHERE diagram_id = @id -- index:83809
    UPDATE sysdiagrams SET [definition] .Write ( 0x4C006F0067005000720069006E007400000008000000700061006C0000000002, null, 0) WHERE diagram_id = @id -- index:83841
    UPDATE sysdiagrams SET [definition] .Write ( 0x2600160000004C006F006700530065007300730069006F006E00000008000000, null, 0) WHERE diagram_id = @id -- index:83873
    UPDATE sysdiagrams SET [definition] .Write ( 0x700061006C00000000022600160000004C006F00670053006500740074006900, null, 0) WHERE diagram_id = @id -- index:83905
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E006700000008000000700061006C00000000022600160000004C006F006700, null, 0) WHERE diagram_id = @id -- index:83937
    UPDATE sysdiagrams SET [definition] .Write ( 0x530075006D006D00610072007900000008000000700061006C00000000022600, null, 0) WHERE diagram_id = @id -- index:83969
    UPDATE sysdiagrams SET [definition] .Write ( 0x180000004C006F00670056006900650077005400790070006500000008000000, null, 0) WHERE diagram_id = @id -- index:84001
    UPDATE sysdiagrams SET [definition] .Write ( 0x700061006C00000000022600160000004C006F0067005700610072006E006900, null, 0) WHERE diagram_id = @id -- index:84033
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E006700000008000000700061006C00000000022600240000004C006F006700, null, 0) WHERE diagram_id = @id -- index:84065
    UPDATE sysdiagrams SET [definition] .Write ( 0x5700610072006E0069006E006700530075006D006D0061007200790000000800, null, 0) WHERE diagram_id = @id -- index:84097
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000700061006C0000000002260010000000500072006F006A00650063007400, null, 0) WHERE diagram_id = @id -- index:84129
    UPDATE sysdiagrams SET [definition] .Write ( 0x00000C0000006100730073006500740000000002260018000000500072006F00, null, 0) WHERE diagram_id = @id -- index:84161
    UPDATE sysdiagrams SET [definition] .Write ( 0x6A00650063007400460069006C00650000001200000073006E00610070007300, null, 0) WHERE diagram_id = @id -- index:84193
    UPDATE sysdiagrams SET [definition] .Write ( 0x68006F00740000000002260028000000500072006F006A006500630074004600, null, 0) WHERE diagram_id = @id -- index:84225
    UPDATE sysdiagrams SET [definition] .Write ( 0x69006C00650053006E0061007000730068006F00740000001200000073006E00, null, 0) WHERE diagram_id = @id -- index:84257
    UPDATE sysdiagrams SET [definition] .Write ( 0x61007000730068006F0074000000000226002A000000500072006F006A006500, null, 0) WHERE diagram_id = @id -- index:84289
    UPDATE sysdiagrams SET [definition] .Write ( 0x6300740049006E0066006F0050006100720061006D0065007400650072000000, null, 0) WHERE diagram_id = @id -- index:84321
    UPDATE sysdiagrams SET [definition] .Write ( 0x1200000073006E0061007000730068006F007400000000022600320000005000, null, 0) WHERE diagram_id = @id -- index:84353
    UPDATE sysdiagrams SET [definition] .Write ( 0x72006F006A0065006300740050006100720061006D0065007400650072004300, null, 0) WHERE diagram_id = @id -- index:84385
    UPDATE sysdiagrams SET [definition] .Write ( 0x61007400650067006F007200790000001200000073006E006100700073006800, null, 0) WHERE diagram_id = @id -- index:84417
    UPDATE sysdiagrams SET [definition] .Write ( 0x6F00740000000002260036000000500072006F006A0065006300740050006100, null, 0) WHERE diagram_id = @id -- index:84449
    UPDATE sysdiagrams SET [definition] .Write ( 0x720061006D00650074006500720044006500660069006E006900740069006F00, null, 0) WHERE diagram_id = @id -- index:84481
    UPDATE sysdiagrams SET [definition] .Write ( 0x6E0000001200000073006E0061007000730068006F0074000000000226001800, null, 0) WHERE diagram_id = @id -- index:84513
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000500072006F006A00650063007400500061007400680000000C0000006100, null, 0) WHERE diagram_id = @id -- index:84545
    UPDATE sysdiagrams SET [definition] .Write ( 0x730073006500740000000002260024000000500072006F006A00650063007400, null, 0) WHERE diagram_id = @id -- index:84577
    UPDATE sysdiagrams SET [definition] .Write ( 0x55006E0075007300650064004900740065006D0000001200000073006E006100, null, 0) WHERE diagram_id = @id -- index:84609
    UPDATE sysdiagrams SET [definition] .Write ( 0x7000730068006F00740000000002260012000000530063006800650064007500, null, 0) WHERE diagram_id = @id -- index:84641
    UPDATE sysdiagrams SET [definition] .Write ( 0x6C00650000001200000073006E0061007000730068006F007400000000022600, null, 0) WHERE diagram_id = @id -- index:84673
    UPDATE sysdiagrams SET [definition] .Write ( 0x1C0000005300630068006500640075006C0065004600690065006C0064000000, null, 0) WHERE diagram_id = @id -- index:84705
    UPDATE sysdiagrams SET [definition] .Write ( 0x1200000073006E0061007000730068006F007400000000022600160000005300, null, 0) WHERE diagram_id = @id -- index:84737
    UPDATE sysdiagrams SET [definition] .Write ( 0x6300680065006D006100440061007400610000000C0000006100730073006500, null, 0) WHERE diagram_id = @id -- index:84769
    UPDATE sysdiagrams SET [definition] .Write ( 0x7400000000022600100000005700610072006E0069006E006700000012000000, null, 0) WHERE diagram_id = @id -- index:84801
    UPDATE sysdiagrams SET [definition] .Write ( 0x73006E0061007000730068006F0074000000000224001000000057006F007200, null, 0) WHERE diagram_id = @id -- index:84833
    UPDATE sysdiagrams SET [definition] .Write ( 0x6B0073006500740000001200000073006E0061007000730068006F0074000000, null, 0) WHERE diagram_id = @id -- index:84865
    UPDATE sysdiagrams SET [definition] .Write ( 0x01000000D68509B3BB6BF2459AB8371664F0327008004E0000007B0031003600, null, 0) WHERE diagram_id = @id -- index:84897
    UPDATE sysdiagrams SET [definition] .Write ( 0x3300340043004400440037002D0030003800380038002D003400320045003300, null, 0) WHERE diagram_id = @id -- index:84929
    UPDATE sysdiagrams SET [definition] .Write ( 0x2D0039004600410032002D004200360044003300320035003600330042003900, null, 0) WHERE diagram_id = @id -- index:84961
    UPDATE sysdiagrams SET [definition] .Write ( 0x310044007D000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:84993
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85025
    UPDATE sysdiagrams SET [definition] .Write ( 0x010003000000000000000C0000000B0000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85057
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85089
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85121
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85153
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85185
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85217
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85249
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85281
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85313
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85345
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85377
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85409
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85441
    UPDATE sysdiagrams SET [definition] .Write ( 0x0000000000000000000000000000000000000000000000000000000000000000, null, 0) WHERE diagram_id = @id -- index:85473
    UPDATE sysdiagrams SET [definition] .Write ( 0x62885214, null, 0) WHERE diagram_id = @id -- index:85505

	
    print '=== Diagram [Diagram_All] restored at diagram_id=' + cast(@id as varchar(10)) + '. ===';
end try
begin catch
    delete from dbo.sysdiagrams where diagram_id = @id;
    print '=== ' + error_message() + ' ===';
end catch;
--End of restore diagram [Diagram_All] script.
 

