MTD

Last Post 18 Dec 2008 08:38 AM by JASBRYDEN. 2 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
JASBRYDEN
New Member
New Member

--
18 Dec 2008 07:28 AM
Hi

I would like to create a field in my table to have MTD.

The MTD has to calculated using 'exprice'

Below is the fields that I currently have, please give me step by step on how to create this MTD field.

Thanks in advance.

Invoice Date exprice excost onhandvalue costofsales budget
20081217 625.91998 443.39401 2659167 1124299 1876000
20081217 0 0 2659167 1124299 1876000
20081217 0 0 78970 0 225000
20081217 -125 0 7627281 7541084 6344000
20081217 750.90002 509.9205 4179225 1340726 1466000
JASBRYDEN
New Member
New Member

--
18 Dec 2008 08:38 AM
Yes I am sorry

I would like to know how to calculate MTD (Month To Date)


I am using SQL 2000, and I would like to know the code to use to generate the MTD sales.

nosepicker
New Member
New Member

--
18 Dec 2008 10:10 AM
Assuming that your table has data for past invoice dates, you can start with something like this:

SELECT SUM(exprice)
FROM YourTable
WHERE [Invoice Date] >= DATEADD(month, DATEDIFF(month, 0, getdate()), 0)
AND [Invoice Date] <= getdate()


You'd have to use GROUP BY if you want to sum the exprices by some other column.
You might also have to either convert [Invoice Date] to the datetime data type, or convert the getdate() to YYYYMMDD if you are storing the invoice dates as YYYYMMDD strings.


Acceptable Use Policy
---