该函数是用来提取年份,月份,日期的一个函数,带两参数,第一个为(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月份的记录
性能上没有做测试。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/16436858/viewspace-630178/ ,如需转载,请注明出处,否则将追究法律责任。