March 20, 2012 at 9:18 am
I'm creating a report through Crystal and I'm needing to get creative. I need to create a data structure to "structurize" a report I'm building.
What I need to do is create a view that has MTD quantities (which will need to be summed up) but I don't have much knowledge of the date functions within TSQL.
Is there a formula I need to use or is there a built in MTD funcion?
March 20, 2012 at 9:34 am
March 20, 2012 at 10:11 am
It's easy to calculate the beginning of the month using the following function.
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)
You can then use that in your CASE expression or WHERE clause as appropriate.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
March 20, 2012 at 11:32 am
drew.allen (3/20/2012)
It's easy to calculate the beginning of the month using the following function.
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)
You can then use that in your CASE expression or WHERE clause as appropriate.
Drew
Using the above combined with this will get all records during the month:
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0)
Used like this:
OrderDate >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) and
OrderDate < DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0)
This can be used in a CASE or WHERE clause.
March 20, 2012 at 12:18 pm
Lynn and Drew,
This is exactly what I was looking for. I appreciate it!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply