python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
pivot in sql server 2008

PIVOT in SQL Server

PIVOT() is used to convert  the rows to columns in SQL Server. 


The example as give below. 

SELECT ISNULL(PVT.JANUARY,'0') AS JANUARY,ISNULL(PVT.FEBRUARY,'0')FEBRUARY,ISNULL(PVT.MARCH,'0')MARCH,
ISNULL(PVT.APRIL,'0')APRIL,ISNULL(PVT.MAY,'0')MAY,ISNULL(PVT.JUNE,'0')JUNE,ISNULL(PVT.JULY,'0')JULY,
ISNULL(PVT.AUGUST,'0')AUGUST,ISNULL(PVT.SEPTEMBER,'0')SEPTEMBER,ISNULL(PVT.OCTOBER,'0') OCTOBER,
ISNULL(PVT.NOVEMBER,'0')NOVEMBER,ISNULL(PVT.DECEMBER,'0') DECEMBER
FROM(SELECT DATENAME(MONTH,CREATEDDATE) AS [MONTH],COUNT(*) AS CCOUNT FROM COMPANY
WHERE TENANTID=1 AND ISNULL(ISDELETED, 0) <> 1
GROUP BY   DATENAME(MONTH,CREATEDDATE)
) AS TMP
PIVOT(SUM(CCOUNT) FOR [MONTH]
IN(JANUARY,FEBRUARY,MARCH,APRIL,MAY,JUNE,JULY,AUGUST,SEPTEMBER,OCTOBER,NOVEMBER,DECEMBER)) AS PVT  
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions