首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

可以简化以下SQL语句吗?该怎么解决

2012-01-26 
可以简化以下SQL语句吗?select[id],totalsum(totalfee),ordercountcount(billid)fromv_billmwhereyear(d

可以简化以下SQL语句吗?
select   [id],total=sum(totalfee),ordercount   =   count(billid)   from   v_billm    
where   year(datecreated)=year(@repdate)  
and   month(datecreated)=month(@repdate)  
and   day(datecreated)=day(@repdate)
and   isreject=0   group   by   [id]

上述语句中日期型数值的比较,能否简化一下啊?
我不能直接用datecreated   =   @repdate
是因为datecreated中含有时分秒,而repdate只含日期.
如果只比较日期部分相等的简单SQL语句啊?

[解决办法]
select [id],total=sum(totalfee),ordercount = count(billid) from v_billm
where convert(char(10),datecreated,120)=convert(char(10),@repdate,120)
and isreject=0 group by [id]
[解决办法]
where datediff(day,datecreated,@repdate)=0 and isreject=0

热点排行