I know this has been asked a bunch of times, but I can't seem to find an answer that will work for me.
I'm trying to get all the dates in a specific range (I'm using week number, but it could be month or whatever) out of the database to use as report headers. I can use the data in the database unless I am on the current week, or there are days without data to report on.
So, I need to get the dates from Sunday to Saturday in any given week based on any given date. I won't be getting a week number, just a date and it won't always be the same day of the week.
What I did that worked to get it out of the data:
And the problem is that there are sometimes dates missing, so it doesn't work nicely for column headers in my report.
How can I do this without referencing my data table?
(Please say there is a way! Otherwise my life will be difficult!)
Thanks!
I'm trying to get all the dates in a specific range (I'm using week number, but it could be month or whatever) out of the database to use as report headers. I can use the data in the database unless I am on the current week, or there are days without data to report on.
So, I need to get the dates from Sunday to Saturday in any given week based on any given date. I won't be getting a week number, just a date and it won't always be the same day of the week.
What I did that worked to get it out of the data:
Code:
declare @mydate as datetime
set @mydate='2008-05-15'
select convert(nchar,enterdate,107) as enterdate from deliveryTable
where datepart(week, enterdate)=datepart(week,@mydate) and
datepart(year, enterdate)=datepart(year,@mydate)
group by convert(nchar,enterdate,107)
How can I do this without referencing my data table?
(Please say there is a way! Otherwise my life will be difficult!)
Thanks!