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

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

2012-11-11 
只利用SQL日期变量的非时间信息进行处理的方法例子SQL Server中日期变量通常包含着日期和时间两块信息,但

只利用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)

 

热点排行