读书人

跪求一条sql语句,怎么取得quot;今日quot;的发表

发布时间: 2012-02-08 19:52:21 作者: rapoo

跪求一条sql语句,如何取得"今日"的发表的数量
数据库是MS-sql
简单的描述就是这样:在表里,
字段有:id title content createTime
createTime 是发表时间,datetime类型
取得发表的文章的全部数量可以用sum,
可是要取得今日的发表数量,如何写这个sql语句??(比如取得今天8月27日发表的文章数量)


兄弟们帮帮忙,立刻给分!

[解决办法]
select count(*) from tablename where createTime > =getdate()
[解决办法]
这样更准一些:
select count(*) from tablename where createTime> =Convert(datetime,year(getdate())+ '- '+month(getdate())+ '- '+day(getdate()))
[解决办法]
select count(*) from tablename where convert(char(10),createTime,20) = convert(char(10),getdate(),20)
[解决办法]
select count(*) from tablename where createTime > =getdate().toshortstring()

[解决办法]
select count(id) from tablename where createTime> = CAST(SUBSTRING(CAST(StartDateTime AS VarChar), 0, 11) AS DateTime) AND createTime < DATEADD(Day,1,CAST(SUBSTRING(CAST(StartDateTime AS VarChar), 0, 11) AS DateTime))
[解决办法]
select count(id) from tablename where createTime> = CAST(SUBSTRING(CAST(getdate() AS VarChar), 0, 11) AS DateTime) AND createTime < DATEADD(Day,1,CAST(SUBSTRING(CAST(getdate() AS VarChar), 0, 11) AS DateTime))

读书人网 >asp.net

热点推荐