Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select Help

Author  Topic 

Makaio780
Starting Member

24 Posts

Posted - 2012-08-10 : 12:35:23
Current Table:

Count | Priority | Classification
32 Low A
41 Medium A
52 High A
30 Critical A
18 Low B
99 Medium B
54 High B
70 Critical B

Query:
Select count(Incident_Number)as Count,Priority,Classification
From vars76_hpd_help_desk inner join
vTbl_Remedy_Group_Classification ON vARS76_HPD_Help_Desk.Assigned_Group = vTbl_Remedy_Group_Classification.Group_Name
where (status = 'Assigned' or status = 'New' or status = 'Pending' or status = 'in progress')
Group by Priority,Classification
ORDER BY Classification



How can i make it so it shows as:


Classification | Low | Medium | High | Critical
A 32 41 52 30
B 18 99 54 70



Ron Cheung

Makaio780
Starting Member

24 Posts

Posted - 2012-08-10 : 12:40:49
Also once i get the data in that format how would i insert that info into a new table?


Ron Cheung
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-10 : 15:42:27
pivot it to get data in desired format

select Classification,[Low],[Medium],[High],[Critical]
from
(
Select Incident_Number,Priority,Classification
From vars76_hpd_help_desk inner join
vTbl_Remedy_Group_Classification ON vARS76_HPD_Help_Desk.Assigned_Group = vTbl_Remedy_Group_Classification.Group_Name
where (status = 'Assigned' or status = 'New' or status = 'Pending' or status = 'in progress')
)t
PIVOT (COUNT(Incident_number) FOR Priority IN ([Low],[Medium],[High],[Critical]))p
ORDER BY Classification


for inserting above into table
just use

INSERT into table
above select statement

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Makaio780
Starting Member

24 Posts

Posted - 2012-08-10 : 16:41:50
Thank you so much!!!

Ron Cheung
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-10 : 17:03:57
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -