Pivot example with from date and to date using SQL Server

Pivot example 

Before going this tutorial Download adventureworks database for sql server 2008 r2

This query will get the count of employees recruited in the company based on from date and to day.


select * from 
(Select --Year(HireDate) as year, 
datename(mm,HireDate)+ ' '+cast(day(HireDate) as varchar) MonthDay,
--count(JobTitle) as TotalEmployees,
JobTitle
from [AdventureWorks2008R2].[HumanResources].[Employee] 
WHERE HireDate BETWEEN '2003-01-15' AND '2003-01-20'
Group by 
 --year(HireDate),
 month(HireDate),
 day(hiredate),
 datename(mm,HireDate),
 JobTitle
 
) 
 p
 PIVOT (count(jobtitle) for 
 MonthDay in ([January 15],[January 16],[January 17])
 ) as pvt

Output: 




Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar