你好我米使用此存儲過程來得到一些信息:2日期之間的SQL SELECT查詢
ALTER proc [dbo].[RevenusStaticAdvanced]
@Days int
as
-------------------------------------------------------------------------------------
select ISNULL(SUM(CAST(TotalPrice as int)),0) as 'TotalPrice',
ISNULL(COUNT(Lavage_Orders.ID),0) as 'Total Commandes'
from Lavage_Orders
inner join LavageTypes on Lavage_Orders.LavageType=LavageTypes.ID
WHERE DATEDIFF(Day,Arrive,GETDATE()) Between 0 and @Days
------------------------------------------------------------------------------------------------
select ISNULL(COUNT(ID),0) as 'TotalCommandes' , ISNULL(SUM(CAST(TotalPrice as int)),0) as 'RevnusRepairs'
from Repair_OrdersDetails
WHERE DATEDIFF(Day,Date,GETDATE()) Between 0 and @Days
------------------------------------------------------------------------------
select ISNULL(SUM(Qte),0) as 'SelledQte' , ISNULL(COUNT(ID),0) as 'TotalCommandes' , ISNULL(SUM(CAST(TotalPrice as int)),0) as 'RevnusAccessoires'
from Accessoires_Order
inner join Accessoires_OrderDetails on Accessoires_OrderDetails.orderID=Accessoires_Order.ID
WHERE DATEDIFF(Day,Date,GETDATE()) Between 0 and @Days
------------------------------------------------------------------------------------------------------
select ISNULL(Accessoires.ID,0), ISNULL(SUM(Accessoires_OrderDetails.Qte),0) as Selled from Accessoires
inner join Accessoires_OrderDetails on Accessoires_OrderDetails.AccessoireID=ID
inner join Accessoires_Order on Accessoires_Order.ID=Accessoires_OrderDetails.orderID
WHERE DATEDIFF(DAY,Accessoires_Order.Date,GETDATE()) Between 0 and @Days
GROUP BY Accessoires.ID
ORDER BY Selled
DESC
這個完美的作品時,我給它的天數(從curret日) 所以我想將其更改爲在2日期之間,因此我將條件更改爲:
WHERE Date Between @Date1 and @Date2
但是這似乎不起作用。
我在C#中傳遞的日期值,如:
public AdvancedStatics AdvancedStaticsView2(DateTime D1,DateTime D2)
{
param[0] = new SqlParameter("@Date1", SqlDbType.DateTime);
param[0].Value = D1;
param[1] = new SqlParameter("@Date2", SqlDbType.DateTime);
param[1].Value = D2;
}
已存儲日期在我的表像:
2017年1月11日14:20:48.177
「這並不似乎是工作」是沒有問題的說明,爲什麼它似乎沒有工作?請注意,「BETWEEN」在兩側都是包含的,沒有時間組件的「datetime」將默認爲午夜。這意味着如果'@ Date1' ='21-03-2017'和'@ Date2' ='23-03-2017',則不會選擇值23-03-2017 14:20:48.177(它大於'23-03-2017 00:00:00.000')。 – HoneyBadger
錯誤是C#代碼,沒有改變它'@ Days'參數 – bradbury9
@HoneyBadger所以我怎麼能改變之間只需要幾天之間 – Huster