该函数是用来提取年份,月份,日期的一个函数,带两参数,第一个为(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月份的记录

性能上没有做测试。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2022-01-13
相关资源
相似解决方案