我在使用日期时间字段进行查询时遇到问题。
这是因为我将 datetime 字段转换为 -varchar(10),..,103- 所以我可以在 103 格式上应用带有日期字段的 where 子句而不是 datetime 但是当我使用 where 子句时它不显示结果或分组我需要的方式,因为日期时间字段已转换为字符串。
以下是该示例的简化查询:
select ddate,SUM(ntotal) as Income from Inc_orders    
where nbranch=2 
and convert(varchar(10),ddate,103)                                   
between '01/06/2010' and '31/06/2010'   
group by convert(varchar(10),ddate,103)  
order by ddfecha desc
ddate 是日期时间字段
ntotal 是整数
nbranch 是外键  
然后发生的是我从另一个 103 日期范围获得结果
01/10/2009  4447.0000    
02/01/2010  26267.8000    
02/02/2010  20498.0000    
02/04/2010  22565.1000   
02/05/2010  20539.0000    
02/11/2010  33934.3000     
02/12/2009  33587.4000   
我假装的样子是:
01/06/2010  29327.7000       
02/06/2010  31170.4000     
03/06/2010  37737.7000     
04/06/2010  25109.6000     
06/06/2010  20819.7000     
10/06/2010  44703.9000     
14/06/2010  21755.1000     
15/06/2010  39369.3000    
05/06/2010  29552.2000    
07/06/2010  35305.9000    
08/06/2010  30628.6000    
..........     
31/06/2010  18677.6000 
解决方案不使用 datepart、month 或 year 函数,因为我需要该参数看起来像日历才能在其上应用 datetimepicker calentad 组合对象。