Print ''
Print '----------------------------------------------------'
Print ' Delete Date Only to be used when cutomised:'
Print ' FirstRevision: V2.0.0   26.06.2012 14:19'
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='uatest03'
 print ''
 Print "Loesche alle ObjectDaten der Site:[" + @SiteId + "]"
 -- Step: loeschen Ergebnisse
 -- Delete top (100) 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
