Difference between revisions of "Sales.vSalesPersonSalesByFiscalYears (view)"
Line 43: | Line 43: | ||
) AS pvt; | ) AS pvt; | ||
</pre> | </pre> | ||
− | |||
== automatically generated == | == automatically generated == | ||
Line 50: | Line 49: | ||
| '''view | | '''view | ||
| Sales.vSalesPersonSalesByFiscalYears | | Sales.vSalesPersonSalesByFiscalYears | ||
− | |- | + | |- valign="top" |
| '''Description | | '''Description | ||
Line 101: | Line 100: | ||
| '''Object Type | | '''Object Type | ||
| '''Dependency Type | | '''Dependency Type | ||
− | + | ||
|- | |- | ||
| [[HumanResources.Employee_(table)|HumanResources.Employee]] | | [[HumanResources.Employee_(table)|HumanResources.Employee]] | ||
Line 122: | Line 121: | ||
| Table | | Table | ||
| Select | | Select | ||
+ | |- | ||
+ | | [[.Sales_(schema)|.Sales]] | ||
+ | | Schema | ||
+ | | Schema | ||
|} | |} |
Revision as of 06:26, 30 November 2009
wikibot
view | Sales.vSalesPersonSalesByFiscalYears |
CREATE VIEW [Sales].[vSalesPersonSalesByFiscalYears] AS SELECT pvt.[SalesPersonID] ,pvt.[FullName] ,pvt.[Title] ,pvt.[SalesTerritory] ,pvt.[2002] ,pvt.[2003] ,pvt.[2004] FROM (SELECT soh.[SalesPersonID] ,c.[FirstName] + ' ' + COALESCE(c.[MiddleName], '') + ' ' + c.[LastName] AS [FullName] ,e.[Title] ,st.[Name] AS [SalesTerritory] ,soh.[SubTotal] ,YEAR(DATEADD(m, 6, soh.[OrderDate])) AS [FiscalYear] FROM [Sales].[SalesPerson] sp INNER JOIN [Sales].[SalesOrderHeader] soh ON sp.[SalesPersonID] = soh.[SalesPersonID] INNER JOIN [Sales].[SalesTerritory] st ON sp.[TerritoryID] = st.[TerritoryID] INNER JOIN [HumanResources].[Employee] e ON soh.[SalesPersonID] = e.[EmployeeID] INNER JOIN [Person].[Contact] c ON e.[ContactID] = c.ContactID ) AS soh PIVOT ( SUM([SubTotal]) FOR [FiscalYear] IN ([2002], [2003], [2004]) ) AS pvt;
automatically generated
view | Sales.vSalesPersonSalesByFiscalYears |
Description | Uses PIVOT to return aggregated sales information for each sales representative. |
CREATE VIEW [Sales].[vSalesPersonSalesByFiscalYears] AS SELECT pvt.[SalesPersonID] ,pvt.[FullName] ,pvt.[Title] ,pvt.[SalesTerritory] ,pvt.[2002] ,pvt.[2003] ,pvt.[2004] FROM (SELECT soh.[SalesPersonID] ,c.[FirstName] + ' ' + COALESCE(c.[MiddleName], '') + ' ' + c.[LastName] AS [FullName] ,e.[Title] ,st.[Name] AS [SalesTerritory] ,soh.[SubTotal] ,YEAR(DATEADD(m, 6, soh.[OrderDate])) AS [FiscalYear] FROM [Sales].[SalesPerson] sp INNER JOIN [Sales].[SalesOrderHeader] soh ON sp.[SalesPersonID] = soh.[SalesPersonID] INNER JOIN [Sales].[SalesTerritory] st ON sp.[TerritoryID] = st.[TerritoryID] INNER JOIN [HumanResources].[Employee] e ON soh.[SalesPersonID] = e.[EmployeeID] INNER JOIN [Person].[Contact] c ON e.[ContactID] = c.ContactID ) AS soh PIVOT ( SUM([SubTotal]) FOR [FiscalYear] IN ([2002], [2003], [2004]) ) AS pvt;
Referenced Object | Object Type | Dependency Type |
HumanResources.Employee | Table | Select |
Person.Contact | Table | Select |
Sales.SalesOrderHeader | Table | Select |
Sales.SalesPerson | Table | Select |
Sales.SalesTerritory | Table | Select |
.Sales | Schema | Schema |