/****** Script for SelectTopNRows command from SSMS  ******/
SELECT j.[TaskId]
      ,j.[TaskState]
      ,j.[ExecutionTimeMs]/1000/60/60 AS ExecutionTimeHours
      ,DATALENGTH(jd.data)/1024.0/1024.0 AS MB
      ,he.Name AS Experiment
      ,he.DateCreated   
      ,u.UserName
      ,j.[LastHeartbeat]
      ,j.[Priority]
      ,j.[CoresNeeded]
      ,j.[MemoryNeeded]
      ,j.[IsPrivileged]
      ,j.[Command]
      ,j.[IsParentTask]   
      ,j.[FinishWhenChildJobsFinished]
      ,j.[ParentTaskId]
      , he.HiveExperimentId
  FROM 
	[HeuristicLab.Hive-3.3].[dbo].[Task] j
	,[HeuristicLab.Hive-3.3].[dbo].[HiveExperiment] he
	,[HeuristicLab.Authentication].dbo.aspnet_Users u
	,[HeuristicLab.Hive-3.3].dbo.TaskData jd
  WHERE
	j.HiveExperimentId = he.HiveExperimentId
	AND j.TaskId = jd.TaskId
	AND he.OwnerUserId = u.UserId
	--AND he.DateCreated > '06-03-2011 10:30'
	
ORDER BY j.TaskState, he.DateCreated DESC