November 28, 2007 at 11:27 am
Hi all,
I am trying to write a query that will only return records with the current weeks date. For example, if it is Wednesday and i run the query, I only want it to return data with Thursday, Friday, and Sat. as its date. If my description is not clear please let me know. I am new to SQL so any input would be greatly appreciated. Thank You.
November 28, 2007 at 11:37 am
Don't fully understand, you saw if Wed you want Thur, Fri, and Sat, what about Sun, Mon and Tues. All in all however look at DATEPART with the wk parameter, this should get you started down the path you are after.
November 28, 2007 at 12:01 pm
You could try something like
[font="Courier New"]select * from Table where DATEPART(wk, DateField) = DATEPART(wk, GETDATE())[/font]
That would give you all rows from this week.
November 28, 2007 at 12:34 pm
Try something like this:
declare @g datetime
declare @startdate datetime
declare @enddate datetime
select @g=cast('11/26/2007' as datetime)
select
date
from
t_date
where
date between
dateadd(day,1,cast(floor(cast(@g as money)) as datetime))
and
dateadd(day,7-(cast(floor(cast(@g as money)) as bigint)+1)%7
,cast(cast(floor(cast(@g as money)) as bigint)-1 as datetime))
--or
select
@startdate=dateadd(day,1,cast(floor(cast(@g as money)) as datetime))
select
@enddate=dateadd(day,7-(cast(floor(cast(@g as money)) as bigint)+1)%7
,cast(cast(floor(cast(@g as money)) as bigint)-1 as datetime))
select
date
from
t_date
where
date between @startdate and @enddate
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply