i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIVOT table in sql server(Power of PIVOT)
12-20-2013, 05:43 AM
Post: #1
PIVOT table in sql server(Power of PIVOT)
Pivot table concept is useful to show the report in a simple and understandable manner for showing or generate reports...

Example for PIVOT :

Suppost we have a EmpOrdtbl table like this

Here Status is 1. Confirm 2. Calllater 3.Cancel

Empid
OrderNo
Mobile
Status

and Values is
Empid Orderno Mobile Status
1 1001 9989789789 Confirm
1 1002 9989758758 Confirm
1 1003 99897897889 Calllater
1 10004 998975758 Cancel
2 10005 99875758 Confirm
2 10006 998975758 CAncel
3 10007 999898899 calllater


Now if we want the Result as

EmpId Confirm Calllater Cancel

Above repot will we get in Using PIVOT in easily

select Empid, [Confirm], [Calllater], [cancel]
from (select EmpId,status from EmpOrdTbl ')as s
pivot (count(status) for status in ([1],[2],[3])) as p



The OUTPUT will be like this

Empid Confirm Calllater Cancel

1 2 1 1
2 1 null 1
3 null null 1


PIVOT is very power full to Generate Report for client requirement

Happy Coding...

for more examples feel free to reply


Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  Difference between SQL Server 2008 R2 and SQL Server 2012 umarali1981 1 14,346 01-02-2013 12:18 PM
Last Post: bhaskarareddy
  Difference between SQL Server 2008 and SQL Server 2012 umarali1981 0 4,521 08-18-2012 04:54 PM
Last Post: umarali1981
  What is the use of SQL Server in share point? arti.porwal20@gmail.com 0 1,466 09-21-2010 11:31 AM
Last Post: arti.porwal20@gmail.com



User(s) browsing this thread: 1 Guest(s)