
IF (SELECT COUNT(*) FROM [master].[cfg].[Identity]) = 0
BEGIN
  INSERT INTO [master].[cfg].[Identity]
             ([Format]
             ,[DnsAlias]
             ,[Remark]
             ,[UpdateDate]
             ,[Customer])
       VALUES
             ('$format'
             ,'$fqdn'
             ,'Initialization DBA'
             ,Default
             ,'$customer')
END
ELSE
BEGIN
  UPDATE [master].[cfg].[Identity]
     SET [Format] =  '$format'
         ,[DnsAlias] = '$fqdn'
         , [Remark] =  'DBA update after Rollout'
		     , [Customer] =  '$customer'
END

IF (SELECT COUNT(*) FROM [master].[cfg].[InstanceContext]) = 0
BEGIN
  INSERT INTO [master].[cfg].[InstanceContext]
             (InstanceContextGuid
			 ,[Type]
             ,[Business]
             ,[Behavior]
             ,[Remark]
             ,[UpdateDate])
       VALUES
             (Newid()
			       ,'$context'
             ,'TPPHAR'
             ,'Enable'
             ,'Initialization DBA'
             ,Default)
END
ELSE
BEGIN
  IF EXISTS(SELECT 1 FROM [master].[cfg].[InstanceContext] WHERE [Type] = 'PREP')
  UPDATE [master].[cfg].[InstanceContext]
     SET [Type] = '$context'
         ,[Business] = 'TPPHAR'
         ,[Behavior] =  'Enable'
         ,[Remark] = 'DBA update after Rollout'
END
