using Pivot to Insert from Select query

I have a Select query that has the following output how do i use a PIVOT to insert into a table with the same field names.

Output from Select Statement:
Count            Fields
-----------------------
101      critical
150265      error
541848      notice
306      warning


Table where data needs to be inserted:
RecordID      int      
ClientNumber      varchar(20)      
DateTime      varchar(20)      
Critical      int      
Alert      int      
Warning      int      
Error      int      
Notice      int      
            

byte1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ralmadaCommented:
something along this line.
 

insert tableb(critical, error, notice, warning)
select [critical], [error], [notice], [warning]
from
(
select fields, count --here goes your current query
from yourtable
) o
pivot(max(count) for fields in ([critical], [error], [notice], [warning]))p

Open in new window

0
ralmadaCommented:
Also, you might want to put the count column name between brackets since "count" is a reserved word in SQL. You should avoid using reserved words to name your columns.
insert tableb(critical, error, notice, warning)
select [critical], [error], [notice], [warning]
from
(
select fields, [count] --here goes your current query
from yourtable
) o
pivot(max([count]) for fields in ([critical], [error], [notice], [warning]))p

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.