你好我米使用此存储过程来得到一些信息: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