该函数是用来提取年份,月份,日期的一个函数,带两参数,第一个为(yy,mm,dd)其中一个,表示年月日,第二个参数为字段名称

比如提取某一年的记录

select *  from Employee  e where  datepart(yy,e.LastLoginTime)=2009

返回2009年所有记录

select *  from Employee  e where  datepart(mm,e.LastLoginTime)=12

返回12月份的所有记录

select *  from Employee  e where  datepart(dd,e.LastLoginTime)=30

返回30号所有记录

SELECT * FROM Employee e  WHERE datepart(mm,e.LastLoginTime)=12  AND  datepart(yy,e.LastLoginTime)=2009

返回09年12月份的记录

性能上没有做测试。

posted on 2010-03-23 11:13  清水道人  阅读(793)  评论(0编辑  收藏  举报