Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Required Output for Quarter

$
0
0

Hi  ,


I have a table that has customer,product,month ,year and month ,information .Sql Scripts

Create Table SampleRevenue
(Customer varchar(30),
 Product  varchar(30),
 SMonth    int ,
 SYear     int,
 Total Decimal )
 go

 
 Insert into SampleRevenue
 Values('Sam','Switch',1,2014,300.50)
 Insert into SampleRevenue
 Values('Sam','Clutch',1,2014,100)
 Insert into SampleRevenue
 Values('Sam','Viper',1,2014,50)
 Insert into SampleRevenue
 Values('Tom','Viper',1,2014,50)
 Insert into SampleRevenue
 Values('Tom','Viper',2,2014,50)
 Insert into SampleRevenue
 Values('Tom','Belt',2,2014,50)
 Insert into SampleRevenue
 Values('Tom','Dash',3,2014,50)
 Insert into SampleRevenue
 Values('Ron','Dash',3,2014,100)
 Insert into SampleRevenue
 Values('Ron','Dash',4,2014,150)
 Insert into SampleRevenue
 Values('Ron','Dash',4,2014,150)
 Insert into SampleRevenue
 Values('Tom','Dash',4,2014,150)
 Insert into SampleRevenue
 Values('Tom','Belt',5,2014,150)
 Insert into SampleRevenue
 Values('Ron','Viper',5,2014,150)
 Insert into SampleRevenue
 Values('Ron','Belt',5,2014,150)
 Insert into SampleRevenue
 Values('Tom','Belt',5,2014,150)
 Insert into SampleRevenue
 Values('Tom','Belt',5,2014,150)
 Insert into SampleRevenue
 Values('Tom','Belt',6,2014,150)

 go

So like if i want to check the result for the current quarter . The output should be like below :

All the current quarter months, Sum of the Product in the customer column and the difference between the months in the current quarter . Kindly Help

Customer Apr-14 May-14 Jun-14 April14 - May14 May 14 - JUNE 14
Ron  300 150 0 250 150
Dash  300 0 0 0 0
Viper 0 150 0 0 0
Tom 150 450 0 -300 450
Dash  150 0 0 . .
Belt  0 450 150 . .



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>