AdventureWorks
Sales.vSalesPersonSalesByFiscalYears View
Description
Uses PIVOT to return aggregated sales information for each sales representative.
Properties
Creation Date08/01/2010 08:41
Is Schema Bound
Encrypted
Ansi Nulls
Columns
 Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
 SalesPersonID int4  
 FullName nvarchar152  
 Title nvarchar50   
 SalesTerritory dbo.Name50   
 2002 money8  
 2003 money8  
 2004 money8  
Objects that Sales.vSalesPersonSalesByFiscalYears depends on
 Database ObjectObject TypeDescriptionDep Level
dbo.AccountNumber datatypedbo.AccountNumberUser Defined Data Type 2
Person.Address tablePerson.AddressTableStreet address information for customers, employees, and vendors.2
Person.Contact tablePerson.ContactTableNames of each employee, customer contact, and vendor contact.1
Person.CountryRegion tablePerson.CountryRegionTableLookup table containing the ISO standard codes for countries and regions.4
Sales.CreditCard tableSales.CreditCardTableCustomer credit card information.2
Sales.Currency tableSales.CurrencyTableLookup table containing standard ISO currencies.3
Sales.CurrencyRate tableSales.CurrencyRateTableCurrency exchange rates.2
Sales.Customer tableSales.CustomerTableCurrent customer information. Also see the Individual and Store tables.2
HumanResources.Employee tableHumanResources.EmployeeTableEmployee information such as salary, department, and title.1
dbo.ErrorLog tabledbo.ErrorLogTableAudit table tracking errors in the the AdventureWorks database that are caught by the CATCH block of a TRY...CATCH construct. Data is inserted by stored procedure dbo.uspLogError when it is executed from inside the CATCH block of a TRY...CATCH construct.3
dbo.Flag datatypedbo.FlagUser Defined Data Type 2
dbo.Name datatypedbo.NameUser Defined Data Type 2
dbo.NameStyle datatypedbo.NameStyleUser Defined Data Type 2
dbo.OrderNumber datatypedbo.OrderNumberUser Defined Data Type 2
dbo.Phone datatypedbo.PhoneUser Defined Data Type 2
Sales.SalesOrderHeader tableSales.SalesOrderHeaderTableGeneral sales order information.1
Sales.SalesPerson tableSales.SalesPersonTableSales representative current information.1
Sales.SalesTerritory tableSales.SalesTerritoryTableSales territory lookup table.1
Purchasing.ShipMethod tablePurchasing.ShipMethodTableShipping company lookup table.2
Person.StateProvince tablePerson.StateProvinceTableState and province lookup table.3
dbo.ufnGetAccountingEndDate functiondbo.ufnGetAccountingEndDateUser Defined FunctionScalar function used in the uSalesOrderHeader trigger to set the starting account date.2
dbo.ufnGetAccountingStartDate functiondbo.ufnGetAccountingStartDateUser Defined FunctionScalar function used in the uSalesOrderHeader trigger to set the ending account date.2
dbo.ufnLeadingZeros functiondbo.ufnLeadingZerosUser Defined FunctionScalar function used by the Sales.Customer table to help set the account number.3
dbo.uspLogError proceduredbo.uspLogErrorStored ProcedureLogs error information in the ErrorLog table about the error that caused execution to jump to the CATCH block of a TRY...CATCH construct. Should be executed from within the scope of a CATCH block otherwise it will return without inserting error information.2
dbo.uspPrintError proceduredbo.uspPrintErrorStored ProcedurePrints error information about the error that caused execution to jump to the CATCH block of a TRY...CATCH construct. Should be executed from within the scope of a CATCH block otherwise it will return without printing any error information.2
View Definition
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;
See Also

Related Objects

Sales Schema
AdventureWorks Database

 

 


© 2012 All Rights Reserved.

Send comments on this topic.