sql - How to get Data from Monday to today's Date -
i have sample data
declare @t table (id int,name varchar(10),dob date) insert @t (id,name,dob) values (1,'mohan','2016-11-13') insert @t (id,name,dob) values (6,'manasa','2016-11-10') insert @t (id,name,dob) values (2,'raj','2016-11-07') insert @t (id,name,dob) values (3,'manny','2016-10-30') insert @t (id,name,dob) values (4,'kamal','2016-11-01') insert @t (id,name,dob) values (5,'raj','2016-11-08')
query :
select * @t dob >= dateadd(wk, datediff(wk,0,getdate()), -1) , dob <= dateadd(wk, datediff(wk,0,getdate()), 5)
here i'm unable monday today's date means 2016-11-10.i'm covering dates coming in week .
i want data
id name dob 6 manasa 2016-11-10 5 raj 2016-11-08
suggest me best way
datename() solve problem.
declare @t table (id int,name varchar(10),dob date) insert @t (id,name,dob) values (1,'mohan','2016-11-13') insert @t (id,name,dob) values (6,'manasa','2016-11-10') insert @t (id,name,dob) values (2,'raj','2016-11-07') insert @t (id,name,dob) values (3,'manny','2016-10-30') insert @t (id,name,dob) values (4,'kamal','2016-11-01') insert @t (id,name,dob) values (5,'raj','2016-11-08') select * @t datename(week,dob) = datename(week,getdate()) go
Comments
Post a Comment