Create View with PIVOT operator

I would like a sample script of using the Pivot operator in a View in T-sql
Howard KatzDatabase Report DeveloperAsked:
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.

Éric MoreauSenior .Net ConsultantCommented:
1
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Éric - Nice job on the article.  Well written.
0
Howard KatzDatabase Report DeveloperAuthor Commented:
I agree that article was clear and well written, but I was asking how to create a View with a PIVOT operator in the view,
Thanks,
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Éric MoreauSenior .Net ConsultantCommented:
Unless your pivot as to be dynamic, just add the query of your pivot into a view like you would do for any other query!

CREATE VIEW [dbo].[View_1]
AS

  SELECT *
  FROM (
	SELECT Computer FROM   dbo.CrashPlanStatus
) AS Source
  PIVOT (COUNT(Computer) FOR Computer IN ([FGLDC04], [FGLDC05], [FGLDC06])) AS Pivoted

GO

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
Howard KatzDatabase Report DeveloperAuthor Commented:
Thank you Eric.  That worked perfectly for me.
0
Éric MoreauSenior .Net ConsultantCommented:
incorrect comment selected
0
Éric MoreauSenior .Net ConsultantCommented:
Howard already said it was working for him!
0
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

From novice to tech pro — start learning today.