Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Multiple Columns to appear on One Row

$
0
0
WE have a query which pulls revenue by country and client for the last 3 years. Right now we have each year being reported in separate columns but we would like to have the revenues for each year for each client to appear on one row. Below is the current query we have setup.SELECT p.country_code, p.local_client_code, wwc.local_client_name, case when pr.fiscal_year = 2015 then sum(pr.local_consulting_fees*er.rate) + sum(pr.local_product_fees * er.rate) + sum(pr.local_admin_fees * er.rate) + sum(pr.local_misc_fees * er.rate) else 0 end as '2015 Revenue', case when pr.fiscal_year = 2014 then sum(pr.local_consulting_fees*er.rate) + sum(pr.local_product_fees * er.rate) + sum(pr.local_admin_fees * er.rate) + sum(pr.local_misc_fees * er.rate) else 0 end as '2014 Revenue', case when pr.fiscal_year = 2013 then sum(pr.local_consulting_fees*er.rate) + sum(pr.local_product_fees * er.rate) + sum(pr.local_admin_fees * er.rate) + sum(pr.local_misc_fees * er.rate) else 0 end as '2013 Revenue'FROM dbo.tblProject pJOIN dbo.tblProject_Revenue pr ON p.project_number = pr.project_number and p.country_code = pr.country_code and p.fiscal_year = pr.fiscal_year JOIN dbo.tblExchange_Rates er ON pr.rept_currency_code = er.currency_code AND er.fiscal_year = pr.fiscal_year AND er.rate_type = 'BUD' JOIN dbo.tblWorldWide_Clients wwc ON p.local_client_code = wwc.local_client_code AND p.country_code = wwc.country_codeJOIN dbo.tblHayGroup_Organization ho ON p.unit_id = ho.unit_code AND ho.automated_status = 'Y' OR ho.country_code IN ('JPN','CHN')GROUP BY pr.fiscal_year,p.country_code,p.local_client_code,wwc.local_client_name

Viewing all articles
Browse latest Browse all 3145

Trending Articles