Print ''
Print '----------------------------------------------------'
Print ' Delete Date Only to be used when cutomised:'
Print ' FirstRevision: V2.0.0   22.03.2006'
Print ' CurrRevision : V2.1.1   11.02.2007'
Print ' Autor        : J.Feuerstein'
Print ' '
Print ' Database Name: #DB_N#'
Print '----------------------------------------------------'
GO

USE [#DB_N#]


--  DECLARE @ExecuteSQLstr nvarchar(max)
 DECLARE @ExecuteSQLstr nvarchar(max)
 DECLARE @SiteId nvarchar(max)

 set @SiteId='Tc83'
 print ''
 Print "Loesche alle ObjectDaten der Site:[" + @SiteId + "]"
 -- Step: loeschen Ergebnisse
 Delete FROM dbo.JobControl_ObjectsProcessData_tbl WHERE ObjectFromSiteID = @SiteId
 -- Step: loeschen ObjectDaten
 Delete FROM dbo.Objects_tbl                       WHERE dbo.Objects_tbl.ObjectFromSiteID = @SiteId

 -- Step: loeschen Oject IR Relations
 delete from  dbo.Objects_Ir_Rel_tbl WHERE dbo.Objects_Ir_Rel_tbl.ID IN
 (
  SELECT
    dbo.Objects_Ir_Rel_tbl.Id
  FROM
    dbo.Objects_Ir_Rel_tbl
    LEFT OUTER JOIN dbo.Objects_tbl ON (dbo.Objects_Ir_Rel_tbl.ObjectId = dbo.Objects_tbl.Id)
  WHERE
    dbo.Objects_tbl.Id IS NULL
 )

GO

Print ''
Print '----------------------------------------------------'
Print ' SQL Script Excetuted on: [#DB_N#]'
Print '----------------------------------------------------'
GO
