[英]Sql Select query Between 2 dates
Hi I m using this Stored procedure to get some informations :嗨,我正在使用这个存储过程来获取一些信息:
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
this works perfectly when i give it a Number of days (from The curret Day ) So i want to change it To between 2 Dates so i changed the Condition to :当我给它一个天数(从当前日开始)时,这非常有效所以我想将它更改为 2 个日期之间,所以我将条件更改为:
WHERE Date Between @Date1 and @Date2
but this doesnt seems to be working .但这似乎不起作用。
i pass the dates value in my c# like :我在我的 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;
}
The Stored Dates in My table like :我表中的存储日期如下:
2017-01-11 14:20:48.177 2017-01-11 14:20:48.177
Your parameters dont match the stored procedure parameters.您的参数与存储过程参数不匹配。
In case you want to pass a number of days:如果您想通过几天:
public AdvancedStatics AdvancedStaticsView2(DateTime D1,DateTime D2)
{
param[0] = new SqlParameter("@Days", SqlDbType.Int);
param[0].Value = 45;
}
In case you want to pass two dates:如果您想传递两个日期:
ALTER proc [dbo].[RevenusStaticAdvanced]
(
@Date1 DateTime,
@Date2 DateTime,
)
as
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.