<?xml version="1.0" encoding="utf-8"?>
<html>
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <link rel="stylesheet" href="../../../css/main.css" type="text/css" />
    <link rel="stylesheet" href="../../../css/jquery.treeview.css" />
    <script src="../../../script/jquery.js" type="text/javascript"></script>
    <script src="../../../script/jquery.cookie.js" type="text/javascript"></script>
    <script src="../../../script/jquery.treeview.js" type="text/javascript"></script>
    <script type="text/javascript">
		                $(document).ready(function(){

		                // first example
		                $("#navigation1").treeview({
			                persist: "location",
			                collapsed: true,
			                unique: true
		                });

		                $("#navigation2").treeview({
			                persist: "location",
			                collapsed: true,
			                unique: true
		                });

		                });
	                </script>
    <title>View</title>
  </head>
  <body>
    <h1>
      <img src="../../../Images/icons/view.png" alt="view icon" /> View: vSalesPersonSalesByFiscalYears</h1>
    <h2>Properties</h2>
    <table id="GetViewList">
      <tr>
        <th>Property</th>
        <th>Value</th>
      </tr>
      <tr>
        <td>Name</td>
        <td>vSalesPersonSalesByFiscalYears</td>
      </tr>
      <tr>
        <td>ID</td>
        <td>1995154153</td>
      </tr>
      <tr>
        <td>Schema</td>
        <td>
          <a href="../../Schemas/Details/Detail_9.html">Sales</a>
        </td>
      </tr>
      <tr>
        <td>Owner</td>
        <td>
          <a href="../../Users/Details/Detail_1.html">dbo</a>
        </td>
      </tr>
      <tr>
        <td>Encrypted</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Schema Bound</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>With Check Option</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>ANSI NULLS</td>
        <td>
          <img src="../../../images/icons/true.png" alt="true" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Uses Quoted Identifier</td>
        <td>
          <img src="../../../images/icons/true.png" alt="true" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Has Opaque Metadata</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Published</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Schema Published</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Replicated</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Has Replication Filter</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Has Unchecked Assembly Data</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Date Correlation View</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Uses Database Collation</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Tracked by CDC</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>MS Shipped</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>Modify Date</td>
        <td>8/8/2010 5:23:46 PM</td>
      </tr>
      <tr>
        <td>Create Date</td>
        <td>8/8/2010 5:23:46 PM</td>
      </tr>
    </table>
    <h2>Extended Properties</h2>
    <table>
      <tr>
        <th>Name</th>
        <th>Value</th>
      </tr>
      <tr>
        <td>MS_Description</td>
        <td>Uses PIVOT to return aggregated sales information for each sales representative.</td>
      </tr>
    </table>
    <h2>View Columns</h2>
    <table>
      <tr>
        <th>Column Name</th>
        <th>Datatype</th>
        <th>Nullable</th>
        <th>Is Identity</th>
      </tr>
      <tr>
        <td>
          <a href="Columns/Column_1995154153_1.html">SalesPersonID</a>
        </td>
        <td>int</td>
        <td>
          <img src="../../../images/icons/true.png" alt="true" class="boolean" />
        </td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>
          <a href="Columns/Column_1995154153_2.html">FullName</a>
        </td>
        <td>nvarchar(152)</td>
        <td>
          <img src="../../../images/icons/true.png" alt="true" class="boolean" />
        </td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>
          <a href="Columns/Column_1995154153_3.html">JobTitle</a>
        </td>
        <td>nvarchar(50)</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>
          <a href="Columns/Column_1995154153_4.html">SalesTerritory</a>
        </td>
        <td>Name</td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>
          <a href="Columns/Column_1995154153_5.html">2002</a>
        </td>
        <td>money</td>
        <td>
          <img src="../../../images/icons/true.png" alt="true" class="boolean" />
        </td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>
          <a href="Columns/Column_1995154153_6.html">2003</a>
        </td>
        <td>money</td>
        <td>
          <img src="../../../images/icons/true.png" alt="true" class="boolean" />
        </td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
      <tr>
        <td>
          <a href="Columns/Column_1995154153_7.html">2004</a>
        </td>
        <td>money</td>
        <td>
          <img src="../../../images/icons/true.png" alt="true" class="boolean" />
        </td>
        <td>
          <img src="../../../images/icons/false.png" alt="false" class="boolean" />
        </td>
      </tr>
    </table>
    <h2>Indexes</h2>
    <span>No view indexes defined.</span>
    <h2>Object Level Permissions</h2>
    <span>No object level permissions defined.</span>
    <h2>Column Level Permissions</h2>
    <span>No explicit column permissions granted to this object</span>
    <h2>Objects that depend on [vSalesPersonSalesByFiscalYears]</h2>
    <ul id="navigation1">
      <li>
        <a href="../../Views/Details/Detail_1995154153.html">Sales.vSalesPersonSalesByFiscalYears</a>
      </li>
    </ul>
    <h2>Objects on which [vSalesPersonSalesByFiscalYears] depends</h2>
    <ul id="navigation2">
      <li>
        <a href="../../Views/Details/Detail_1995154153.html">Sales.vSalesPersonSalesByFiscalYears</a>
        <ul>
          <li>
            <a href="../../Tables/Details/Detail_981578535.html">HumanResources.Employee</a>
            <ul>
              <li>
                <a href="../../Datatypes/Details/Detail_258.html">dbo.Flag</a>
              </li>
              <li>
                <a href="../../Tables/Details/Detail_1509580416.html">Person.Person</a>
                <ul>
                  <li>
                    <a href="../../Datatypes/Details/Detail_260.html">dbo.Name</a>
                  </li>
                  <li>
                    <a href="../../Datatypes/Details/Detail_259.html">dbo.NameStyle</a>
                  </li>
                  <li>Demographics.exist</li>
                  <li>
                    <a href="../../XmlSchemaCollections/Details/Detail_65536.html">Person.AdditionalContactInfoSchemaCollection</a>
                  </li>
                  <li>
                    <a href="../../Tables/Details/Detail_341576255.html">Person.BusinessEntity</a>
                  </li>
                  <li>
                    <a href="../../XmlSchemaCollections/Details/Detail_65537.html">Person.IndividualSurveySchemaCollection</a>
                  </li>
                </ul>
              </li>
            </ul>
          </li>
          <li>
            <a href="../../Tables/Details/Detail_1010102639.html">Sales.SalesOrderHeader</a>
            <ul>
              <li>
                <a href="../../Datatypes/Details/Detail_257.html">dbo.AccountNumber</a>
              </li>
              <li>
                <a href="../../Datatypes/Details/Detail_261.html">dbo.OrderNumber</a>
              </li>
              <li>
                <a href="../../Functions/Details/Detail_2123154609.html">dbo.ufnGetAccountingEndDate</a>
              </li>
              <li>
                <a href="../../Functions/Details/Detail_2107154552.html">dbo.ufnGetAccountingStartDate</a>
              </li>
              <li>
                <a href="../../Procedures/Details/Detail_53575229.html">dbo.uspLogError</a>
                <ul>
                  <li>
                    <a href="../../Tables/Details/Detail_2137058649.html">dbo.ErrorLog</a>
                  </li>
                  <li>
                    <a href="../../Procedures/Details/Detail_37575172.html">dbo.uspPrintError</a>
                  </li>
                </ul>
              </li>
              <li>
                <a href="../../Tables/Details/Detail_85575343.html">Person.Address</a>
                <ul>
                  <li>
                    <a href="../../Tables/Details/Detail_206623779.html">Person.StateProvince</a>
                    <ul>
                      <li>
                        <a href="../../Tables/Details/Detail_549576996.html">Person.CountryRegion</a>
                      </li>
                      <li>
                        <a href="../../Tables/Details/Detail_1666104976.html">Sales.SalesTerritory</a>
                      </li>
                    </ul>
                  </li>
                </ul>
              </li>
              <li>
                <a href="../../Tables/Details/Detail_1970106059.html">Purchasing.ShipMethod</a>
              </li>
              <li>
                <a href="../../Tables/Details/Detail_581577110.html">Sales.CreditCard</a>
              </li>
              <li>
                <a href="../../Tables/Details/Detail_677577452.html">Sales.CurrencyRate</a>
                <ul>
                  <li>
                    <a href="../../Tables/Details/Detail_645577338.html">Sales.Currency</a>
                  </li>
                </ul>
              </li>
              <li>
                <a href="../../Tables/Details/Detail_709577566.html">Sales.Customer</a>
                <ul>
                  <li>
                    <a href="../../Functions/Details/Detail_69575286.html">dbo.ufnLeadingZeros</a>
                  </li>
                  <li>
                    <a href="../../Tables/Details/Detail_270624007.html">Sales.Store</a>
                    <ul>
                      <li>
                        <a href="../../Tables/Details/Detail_1298103665.html">Sales.SalesPerson</a>
                      </li>
                      <li>
                        <a href="../../XmlSchemaCollections/Details/Detail_65541.html">Sales.StoreSurveySchemaCollection</a>
                      </li>
                    </ul>
                  </li>
                </ul>
              </li>
            </ul>
          </li>
        </ul>
      </li>
    </ul>
    <h2>SQL</h2>
    <table>
      <tr>
        <th>Script</th>
      </tr>
      <tr>
        <td>SET ANSI_NULLS ON<br />SET QUOTED_IDENTIFIER ON<br />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;
<br />EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Uses PIVOT to return aggregated sales information for each sales representative.' , @level0type=N'SCHEMA',@level0name=N'Sales', @level1type=N'VIEW',@level1name=N'vSalesPersonSalesByFiscalYears'<br /></td>
      </tr>
    </table>
    <h4 class="seealso">See also</h4>
    <a href="../General.html">List of Views</a>
  </body>
</html>