My apologies. the correct query should be
Select Top 1 'v961' as Recipe, BTB_Secs, Count(BTB_Secs) as DCount
from (SELECT RecipeName, DATEDIFF(ss, LAG([Date]) OVER (ORDER BY ID), [Date])as BTB_Secs
FROM [Millroom].[BizUser].[Ban1_Data]
where recipename = 'v961' and processtime <480
) T
group by BTB_Secs order by dcount desc
Union
Select Top 1 'X331' as Recipe, BTB_Secs, Count(BTB_Secs) as DCount
from (SELECT RecipeName, DATEDIFF(ss, LAG([Date]) OVER (ORDER BY ID), [Date])as BTB_Secs
FROM [Millroom].[BizUser].[Ban1_Data]
where recipename = 'X331' and processtime <480
) T
group by BTB_Secs order by dcount desc
running this query results in a syntax error. running the query. running the query singularly produces the correct result. removing the order by clause before the Union produces the incorrect result. sorry..hope this makes sense.