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
 Sum

Author  Topic 

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2014-04-08 : 17:47:27
Hi, I' have s sql view that shows me the all the sales for a customer on the last 3 months:

DebCode,Debtor,Total,Subtotal,Vat,Profit,Margin,Year,Month

Mi problem is that I need one column per month but I need 2 amounts : Profit and Margin, how can I do this?

I have this :
|DebCode|Debtor|Margin|Profit|Year|Month|
| 100 |Deb100| 25 |500.00|2014| 01 |
| 100 |Deb100| 15 |350.00|2014| 02 |
| 100 |Deb100| 15 |350.00|2014| 02 |
| 100 |Deb100| 25 |500.00|2014| 03 |

This is my code :

SELECT     DebCode, Debtor, City, Sector, Year, Month, Subtotal_PES, Cost_PES, Vat_PES, Total_PES, Margin, SUM(Subtotal_PES) - SUM(Cost_PES) AS Profit, SaleRep
FROM dbo.View_VK_SALES_SUMARY
GROUP BY DebCode, Debtor, Year, Month, Subtotal_PES, Cost_PES, Vat_PES, Total_PES, Margin, SaleRep, City, Sector


Thank you so much...

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2014-04-09 : 10:36:07
How can I Controll this If I have 3 Columns [JAN],[FEB],[MAR] and I need two Amount per month: Profit and Margin?

Please somebody helps me and tell me what options I have.

Thanks in advance.
Go to Top of Page

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2014-04-09 : 12:06:13
I was thinking on this idea, put together in each column the two amounts, Profit and Margin, is this possible? :

| JAN | FEB | MAR |
|$20,000 (28%) |$10,000 (14%)|$15,000 (18%)|

Any idea?

Go to Top of Page
   

- Advertisement -