752
社区成员
发帖
与我相关
我的任务
分享
create table tb(id int, csrq datetime)
insert into tb values(1, '1977-01-11')
insert into tb values(2, '1968-01-09')
insert into tb values(3, '1966-01-01')
go
select id , csrq from tb
where datediff(day , getdate() , datename(year,getdate()) + substring(convert(varchar(10),csrq,120),5,6)) between 0 and 7
drop table tb
/*
id csrq
----------- -----------------------
1 1977-01-11 00:00:00.000
2 1968-01-09 00:00:00.000
(2 行受影响)
*/
select id , csrq from tb
where datediff(day , getdate() , datename(year,getdate()) + substring(convert(varchar(10),csrq,120),5,5)) <= 7