Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Rolling total per month

Author  Topic 

bobred
Starting Member

14 Posts

Posted - 2014-12-01 : 05:10:38
Hi

We have an inventory of devices we service and wish to show the total numbers of active devices per month going 12 months back.

How would I go about this?

James

sunder.bugatha
Yak Posting Veteran

66 Posts

Posted - 2014-12-01 : 09:31:12
Can you share sample data?

Hema Sunder
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2014-12-01 : 09:44:48
Something like this:

Declare @MonthPast12 Date = Dateadd(MONTH, -12, InventoryDate)
Select
DeviceName,
DateName(Month, [InventoryDate]) 'MonthName',
Count([DeviceName]) 'DeviceTotal'

From Inventory
Where [InventoryDate] <= [@MonthPast12]
Group By [DeviceName], [InventoryDate]
Go

We are the creators of our own reality!
Go to Top of Page
   

- Advertisement -