Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Top Five Records Question?

Status
Not open for further replies.

mptwoadmin

Programmer
May 15, 2006
46
US
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
 
Perhaps a data example and the expected out come would help visualize the problem.

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top