mptwoadmin
Programmer
Hi I am trying to figure how to get the top 5 records through my query below but am unable to come to the right solution in SQL. Can someone lend a hand please?
SELECT sum(isnull(value_2,0)-isnull(value_1,0)) as "Weight Difference"
FROM
(
select(select top 1 nullif(isnull(value,0),0)
from AnalogHistory
where TagName in ('tank')
and datetime = dateadd(n,-15,getdate()) and Value > 0 and Value is not null) as value_1,
(select top 1 nullif(isnull(value,0),0)
from AnalogHistory
where TagName in ('tank')
and datetime = getdate() and Value > 0 and Value is not null) as value_2
) total
Thank You
SELECT sum(isnull(value_2,0)-isnull(value_1,0)) as "Weight Difference"
FROM
(
select(select top 1 nullif(isnull(value,0),0)
from AnalogHistory
where TagName in ('tank')
and datetime = dateadd(n,-15,getdate()) and Value > 0 and Value is not null) as value_1,
(select top 1 nullif(isnull(value,0),0)
from AnalogHistory
where TagName in ('tank')
and datetime = getdate() and Value > 0 and Value is not null) as value_2
) total
Thank You