AdventureWorks2012 View Needs Update
-
19 กรกฎาคม 2555 20:06
The OrderDate in Sales.SalesOrderHeader has been advanced 4 years to 2005 to 2008. However, the vSalesPersonSalesByFiscalYears view definition remained the old. The years ([2002], [2003], [2004]) must be bumped up to ([2006], [2007], [2008])
CREATE VIEW [Sales].[vSalesPersonSalesByFiscalYears] AS SELECT pvt.[SalesPersonID] ,pvt.[FullName] ,pvt.[JobTitle] ,pvt.[SalesTerritory] ,pvt.[2002] ,pvt.[2003] ,pvt.[2004] FROM (SELECT soh.[SalesPersonID] ,p.[FirstName] + ' ' + COALESCE(p.[MiddleName], '') + ' ' + p.[LastName] AS [FullName] ,e.[JobTitle] ,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.[BusinessEntityID] = soh.[SalesPersonID] INNER JOIN [Sales].[SalesTerritory] st ON sp.[TerritoryID] = st.[TerritoryID] INNER JOIN [HumanResources].[Employee] e ON soh.[SalesPersonID] = e.[BusinessEntityID] INNER JOIN [Person].[Person] p ON p.[BusinessEntityID] = sp.[BusinessEntityID] ) AS soh PIVOT ( SUM([SubTotal]) FOR [FiscalYear] IN ([2002], [2003], [2004]) ) AS pvt;
Kalman Toth SQL SERVER 2012 & BI TRAINING
New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2012- แก้ไขโดย Kalman TothMicrosoft Community Contributor 19 กรกฎาคม 2555 20:09
- แก้ไขโดย Kalman TothMicrosoft Community Contributor 13 ตุลาคม 2555 18:10
ตอบทั้งหมด
-
24 กรกฎาคม 2555 7:32ผู้ดูแล
Hi SQLUSA,
Thanks for sharing your idea!
Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
- ทำเครื่องหมายเป็นคำตอบโดย Kalman TothMicrosoft Community Contributor 27 กรกฎาคม 2555 5:41