var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: How to pull current month data from table updated daily
Hey folks, novice programmer, first time forum user:
I have a table thats updated daily with monthly data totals:
Month, Total orders1, Total orders2, etc
12/01/2012, 5, 8, etc
11/01/2012, 6, 5, etc
How do I pull data from this table in SQL Server for ONLY the current month? I was thinking using the getdate() function to get the current month, but it doesn't match exactly so I get no results
By the way, "Month" is a reserved word in SQL Server.
where [month] = convert(date, dateadd (dd, -1 * datepart(dd, getdate()) + 1, getdate()))
Thank you, the column name is actually ordermonth, I was just trying to shorten it a bit.
I tried that code but got this error msg:
Server: Msg 243, Level 16, State 1, Line 1
Type date is not a defined system type.
where OrderMonth >= DATEADD(month, DATEDIFF(month, '1900-01-01', getdate()), '1900-01-01') --Returns current month
and OrderMonth < DATEADD(month, DATEDIFF(month, '1900-01-01', getdate())+1, '1900-01-01') --Returns next month
That worked perfectly! Thank you!!
One question tho..I figured out this little bit on my own and it seems to work:
WHERE datepart(mm,ordermonth) =
Is there any reason why this would be any better or worse than Blindman's suggestion? Again, I'm brand new at this stuff, so I'm just trying to figure out what does what and how..
Thank you again!
Last edited by JayGrrr; 12-11-12 at 18:09.
Oh, mine returns data for every year w current month in date, not just current month.. Crap. Got it.
Why do people use system reserved words as a column name.. I learned in college to stay away after spending an entire weekend diagnosing why my access database connection wasn't working with java.
I still feel the pain to this day.
Because Microsoft reserved all the best words.