Using Microsoft SQL 2008. I have two tables that I want to select from the current date to the first day of that month (or within the same month). Let’s say today’s date is 05/09/2012 and the date column is ‘datecolumn’. Fom the tables below I should only get rowsets 6,7 from table1 and rowsets 9,2 from table 2 because those dates are within the same month as 05/09/2012.
table1
4 02/01/2012
5 01/02/2011
6 05/01/2012
7 05/20/2012
table2
8 02/01/2012
9 05/14/2012
3 01/02/2011
2 05/18/2012
I tried this but it didnt work:
DECLARE @daterange
SET @daterange = (DATEPART(MONTH,GETDATE()) + '/' + DATEPART(YEAR,GETDATE()))
SELECT blah from table where (DATEPART(MONTH,datecolumn) + '/' + DATEPART(YEAR,datecolumn)) = @daterange
You can simplify it, no need to reconstitute the date field from
GETDATE():