您的位置:首页 > 数据库

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

2012-11-04 02:35 344 查看
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐