当前位置: 代码迷 >> SQL >> 只利用SQL日期变量的非时间信息进展处理的方法例子
  详细解决方案

只利用SQL日期变量的非时间信息进展处理的方法例子

热度:66   发布时间:2016-05-05 12:56:35.0
只利用SQL日期变量的非时间信息进行处理的方法例子

SQL Server中日期变量通常包含着日期和时间两块信息,但是在很多处理中我们并不需要时间信息,此时可以利用转换函数舍弃时间信息并只保留日期信息,如

convert(char(10),date1,111)

将日期变量date1的转换成诸如2012/11/03这样的形式

 

借此方法,可以实现更多功能,如下面的语句可以查询newlendfull表中每条记录中date1和date2日期之间发生的其他记录个数,汇总统计并更新到现有的每记录midcount字段中

update newlendfull set midcount=(select count(distinct convert(char(10),date1,111)) from newlendfull a
where convert(char(10),date1,111)>convert(char(10),newlendfull.date1,111) and  convert(char(10),date1,111)<convert(char(10),newlendfull.date2,111) and  a.rid=newlendfull.rid)

 

  相关解决方案