SQL Server 中 datepart 函数的使用

SQL Server 中 datepart 函数的使用,第1张

概述该函数是用来提取年份,月份,日期的一个函数,带两参数,第一个为(yy,mm,dd)其中一个,表示年月日,第二个参数为字段名称比如提取某一年的记录 select * from Employee e where datepart(yy,e.LastLoginTime)=2009 返回2009年所有记录 select * from Employee e where datepart(mm,e.LastLog… 该函数是用来提取年份,月份,日期的一个函数,带两参数,第一个为(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月份的记录

性能上没有做测试。

总结

以上是内存溢出为你收集整理的SQL Server 中 datepart 函数的使用全部内容,希望文章能够帮你解决SQL Server 中 datepart 函数的使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1151344.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存