/****** Script for SelectTopNRows command from SSMS ******/
SELECT CM_TC1.dbo.v_R_System.Name0, CAST(CM_TC1.dbo.v_TaskExecutionStatus.ExecutionTime as date ), Max(CM_TC1.dbo.v_TaskExecutionStatus.Step)
FROM CM_TC1.dbo.v_TaskExecutionStatus INNER JOIN
CM_TC1.dbo.v_R_System ON CM_TC1.dbo.v_TaskExecutionStatus.ResourceID = CM_TC1.dbo.v_R_System.ResourceID LEFT OUTER JOIN
CM_TC1.dbo.v_Advertisement ON CM_TC1.dbo.v_TaskExecutionStatus.AdvertisementID = CM_TC1.dbo.v_Advertisement.AdvertisementID
Group by CM_TC1.dbo.v_R_System.Name0,CAST(CM_TC1.dbo.v_TaskExecutionStatus.ExecutionTime as date )
/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP (1000) CM_TC1.dbo.v_R_System.Name0, CM_TC1.dbo.v_Advertisement.AdvertisementName, CM_TC1.dbo.v_TaskExecutionStatus.Step,
CM_TC1.dbo.v_TaskExecutionStatus.ActionName, CM_TC1.dbo.v_TaskExecutionStatus.LastStatusMessageIDName, CM_TC1.dbo.v_TaskExecutionStatus.ExitCode,
CM_TC1.dbo.v_TaskExecutionStatus.ActionOutput, CM_TC1.dbo.v_TaskExecutionStatus.ExecutionTime, CM_TC1.dbo.v_TaskExecutionStatus.ResourceID
FROM CM_TC1.dbo.v_TaskExecutionStatus INNER JOIN
CM_TC1.dbo.v_R_System ON CM_TC1.dbo.v_TaskExecutionStatus.ResourceID = CM_TC1.dbo.v_R_System.ResourceID LEFT OUTER JOIN
CM_TC1.dbo.v_Advertisement ON CM_TC1.dbo.v_TaskExecutionStatus.AdvertisementID = CM_TC1.dbo.v_Advertisement.AdvertisementID
ORDER BY CM_TC1.dbo.v_TaskExecutionStatus.ExecutionTime DESC