salliven (5/4/2016)
Maybe this query?
;with cte as (
select TOP (select ((MD.TotalCount*80)/100) as TotalCount from [dbo].[Message_Identifier] MD where MD.MessageID = 1141)
DMQD.SubmitDate
from [dbo]. message_queue_details
DMM DMM.MessageID = 1141
order by SubmitDate
)
select
DATEDIFF(SECOND,MIN(SubmitDate), MAX(SubmitDate)) as TimeDiff
from cte
I think, you need to use order by (in original query too).
The TOP clause takes an optional PERCENT keyword, so you could write this as
;with cte as (
select TOP (80) PERCENT
DMQD.SubmitDate
from [dbo]. message_queue_details
DMM DMM.MessageID = 1141
order by SubmitDate
)
select
DATEDIFF(SECOND,MIN(SubmitDate), MAX(SubmitDate)) as TimeDiff
from cte
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA