开发者

SQL Query to calculate the difference of a number of fields and passing to ASP script

开发者 https://www.devze.com 2023-02-05 21:24 出处:网络
My query as it stands at the moment: SELECT RemainingCapacityBytes FROM [Check].[dbo].[tbl_BackupChecks_MediaInfo]

My query as it stands at the moment:

SELECT RemainingCapacityBytes
  FROM [Check].[dbo].[tbl_BackupChecks_MediaInfo]
  WHERE Company = 'Company Name' and ModifiedDateTime >= dateadd(d,-7,GETDATE())

This returns a number of results that are integer values. I'm not sure if this is possible but what I would like to do is have SQL calculate the difference of the above returned results (by taking the highest and lowest value) and then pass the caluclated answer variable back to the ASP script the query is running in. I will put an example below

RemainingCapacityBytes
----------------------
500293821
920392832
192837282
192837283
010299开发者_JAVA百科999

The query would calculate the highest number 500293821 - the lowest 010299999 and then return the answer.

I don't think this is possible and I think I will probably end up just doing it in the ASP script but I thought I'd ask the experts first.


Try this:

SELECT MAX(RemainingCapacityBytes) - MIN(RemainingCapacityBytes) DiffCapacityBytes
   FROM [Check].[dbo].[tbl_BackupChecks_MediaInfo]   
 WHERE Company = 'Company Name' and ModifiedDateTime >= dateadd(d,-7,GETDATE()) 
0

精彩评论

暂无评论...
验证码 换一张
取 消