select datepart(weekday,cast('20090202' as datetime)+ @@datefirst-1)
结果是:1,不会显示星期一
由此查询2009-02-02是星期几
扩展一下,查询一个订单表,哪些订单是星期二生成的:
SELECT ID,orderdate
FROM [orders]
WHERE DATEPART(weekday,orderdate+@@DATEFIRST-1)=2
select datepart(weekday,cast('20090202' as datetime)+ @@datefirst-1)
结果是:1,不会显示星期一
由此查询2009-02-02是星期几
扩展一下,查询一个订单表,哪些订单是星期二生成的:
SELECT ID,orderdate
FROM [orders]
WHERE DATEPART(weekday,orderdate+@@DATEFIRST-1)=2