我要做的是计算更新2天的表的行数意味着我有一些这样的数据:
ID Name Department DateTime ModifyDate
---------------------------------------------------------------------------
1 XXXXX IT 2013-09-10 09:53:01.000 2013-09-10 09:55:01.000
2 YYYYY Tech 2013-09-09 10:00:00.000 2013-09-10 12:00:00.000
3 WWWW IT 2013-09-09 08:09:00.000 2013-09-10 09:09:00.000
现在有两行可以修改10 sep
我想要一个查询,它会给我数不。每天修改一行。
我想要的就像这样
No. of column
2
答案 0 :(得分:1)
试试这个
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("Select count(ID) from TableName where ModifyDate>=@Today and ModifyDate<@NextDay", connection))
{
command.Parameters.Add(new SqlParameter("Today", DateTime.Today ));
command.Parameters.Add(new SqlParameter("Nextday", DateTime.Today.AddDays(1) ));
int count = 0;
int.TryParse( command.ExecuteScalar().ToString() , out count);
}
}
答案 1 :(得分:1)
select Distinct Count(ID) from Table where ModifyDate between '2013-09-10' and '2013-09-11'
答案 2 :(得分:1)
SELECT COUNT(ID) FROM TableX WHERE ModifyDate BETWEEN @FromDate and @ToDate;
将您的开始和结束日期传递给相应的变量
答案 3 :(得分:0)
您可能想要使用类似
的内容SELECT count(ID)
FROM TableName
GROUP BY CAST(ModifyDate AS DATE)
答案 4 :(得分:0)
select count(*) as [No. of column] from Table1
where CAST(ModifyDate as Date) = 'Sep 10, 2013'
如果您想要过滤当前日期,请使用GetDate()替换“2013年9月10日”。
答案 5 :(得分:0)
SELECT CONVERT(DATE,ModifiedDate) AS DATE, count(ID) AS TotalUpdated
FROM TableName
GROUP BY CONVERT(DATE,ModifiedDate)
尝试此查询。