thomas thomas - 10 months ago 46
SQL Question

SQL query seconds to date (Ssms12)

on the stackoverflow site in fount Thad

select CONVERT(CHAR(10), DATEADD(second, MAX(60), 0), 108)
will result in 00:01:00 (that's true btw :-) )

now I want to integrate this in the following query (for Ssms12):

SELECT Run.TaskName,history.runtime
,CONVERT(CHAR(10), DATEADD(second, MAX(history.runtime), 0), 108)

FROM dbo.history
ON dbo.history.TaskID=Run.TaskID

whatever I try, I can't get this to work in the above example, does anyone have an idea how to fix this?

error: Column 'Run.TaskName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Answer Source

Most probably you needn't MAX. select CONVERT(CHAR(10), DATEADD(second, 60, 0), 108) is OK, so

SELECT Run.TaskName,history.runtime
      ,CONVERT(CHAR(10), DATEADD(second, history.runtime, 0), 108)
FROM dbo.history 
    ON dbo.history.TaskID=dbo.Run.TaskID