提取数据超过一个月,但每月显示一行

时间:2013-02-12 18:41:00

标签: sql-server-2008 crystal-reports-2008

我有2个SQL语句用于将数据提取到水晶报表中。它从用户放置过滤器的结束日期开始提取一个月的数据。现在我被要求撤回相同的数据,但每个月都适合他们输入的日期范围。一个声明是第一天,另一个是本月的最后一天。

(SELECT TOP   1
Max(Meter_Reading)  
FROM [Forefront].[dbo].[EC_METER_HISTORY_MC] 
where Company_Code = "EC_METER_HISTORY"."Company_Code" 
AND Equipment_Code = "EC_METER_HISTORY"."Equipment_Code" 
and Meter_Number = '1' 
and Transaction_Date = 
(select MAX(transaction_date) 
FROM [Forefront].[dbo].[EC_METER_HISTORY_MC] 
where 
Company_Code = "EC_METER_HISTORY"."Company_Code" AND
Equipment_Code = "EC_METER_HISTORY"."Equipment_Code" and
Meter_Number = '1' and Transaction_Date < 
(SELECT CONVERT(DATE,DATEADD(dd,-(DAY    ("CL_TEMP_VARIABLES"."Short_Alpha_6")),"CL_TEMP_VARIABLES"."Short_Alpha_6"),101)))

)






 (SELECT TOP   1
  Max(Meter_Reading)  
  FROM [Forefront].[dbo].[EC_METER_HISTORY_MC] 
  where Company_Code = "EC_METER_HISTORY"."Company_Code" 
  AND Equipment_Code = "EC_METER_HISTORY"."Equipment_Code" 
  and Meter_Number = '1' 
  and Transaction_Date = 
  (select MAX(transaction_date) 
 FROM [Forefront].[dbo].[EC_METER_HISTORY_MC] 
where 
 Company_Code = "EC_METER_HISTORY"."Company_Code" AND
Equipment_Code = "EC_METER_HISTORY"."Equipment_Code" and
Meter_Number = '1' and Transaction_Date <
(SELECT CONVERT(DATE,DATEADD(dd,-(DAY(DATEADD(mm,1,"CL_TEMP_VARIABLES"."Short_Alpha_6"))),DATEADD  (mm,1,"CL_TEMP_VARIABLES"."Short_Alpha_6")),101)))
)

0 个答案:

没有答案