SELECT TOP #JobObjectsN#
 Objects_tbl.*,
 Ir.ObjectPuid AS IrPuid,
 Ir.ObjectName AS IrName
FROM
 dbo.Objects_tbl WITH (nolock)
 LEFT OUTER JOIN dbo.Objects_Ir_Rel_tbl WITH (nolock) ON (dbo.Objects_tbl.Id = dbo.Objects_Ir_Rel_tbl.ObjectId)
 LEFT OUTER JOIN dbo.Objects_tbl Ir WITH (nolock) ON (dbo.Objects_Ir_Rel_tbl.IrId = Ir.Id)
WHERE
 Objects_tbl.ObjectClass='DS'
 -- see if Rf (ProcStateCol20) ended with OK or or WRN
 AND (Objects_tbl.ProcStateCol20 like 'D.%OK' or Objects_tbl.ProcStateCol20 like 'D.%WRN')
-- AND Objects_tbl.ProcStateCol15 = 'N'
 AND (Objects_tbl.ProcStateCol15 = 'RUN.K2' or Objects_tbl.ProcStateCol15 = 'N')
 AND Objects_tbl.ObjectOwningSiteID='#TcSiteId#'
-- AND Objects_tbl.ObjectLastModDate<=Convert(datetime,'2012-01-01 00:00:00',120)
--  AND Objects_tbl.ObjectUgMaster_Type = 'AP'
-- AND Objects_tbl.ObjectUgMaster_Type = 'SP'
 AND Objects_tbl.ObjectIrLatestRank=-1

