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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 t-sql on rolling 3 month period

Author  Topic 

ziggy2015
Starting Member

11 Posts

Posted - 2015-04-12 : 07:15:15
Hi Guys,

I need your help on how to write sql on months total sales volume and variance.

I want to calculate 3 months from today excluding the current month as I there is no data.

Thanks

Ziggy

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-04-12 : 14:27:42
please post your table definition (CREATE TABLE statement), some sample data (as INSERT INTO commands) and your desired results, using the sample data
Go to Top of Page

ziggy2015
Starting Member

11 Posts

Posted - 2015-04-13 : 02:53:16
Thanks. My table looks like:

Select Year
,Month
,Date
,Sum(Total) As Count
,OrganizationCode
,ProviderCode

From TblVolume
Group by Year
,Month
,Date
,OrganizationCode
,ProviderCode

I need a three months rolling period and comparing current month and previous 2 months.

Thanks
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-04-13 : 08:56:25
Please post the other requested items:

1. CREATE TABLE statement (that is NOT a select statement)
2. INSERT INTO statements to populate the table with test data
3. Your desired results, using the table and test data from steps 1 and 2
Go to Top of Page
   

- Advertisement -