SQL - query issue


I have a GridView on my web form  with the SQL table shown in the following image bound to it. I need to get the data into the format in the second image. What SQL or technique would I use to do this. The second image doesn't show the X values but I plan to show them there:

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
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.

In SQL that would be termed a "pivot", and it can be achieved using SQL

Is the number of columns always the same?
or are you expecting the number of columns to increase/decrease?
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
The number of columns changes
>>Q. What SQL or technique would I use to do this.
= Pivot

>>extra: The number of columns changes
This leads to a need to what is known as "dynamic sql"
essentially it is a query that concatenates information together, and the information happens to be the next sql statement.

you then execute that "dynamically generated" sql statement

if you search here at EE for "dynamic pivot tsql" you will see many Questions and Answers on that topic, if you would like to see some example.

What I would suggest now is  that you prepare a new question.
Identify the tables and fields involved
provide some sample data (is a reusbale format, not an image)
and an expected result
specify that the number of columns has to be 'dynamic'

perhaps title the question as:

Need help with dynamic pivot in TSQL

one last thing.
the term "pivot" is generic
but there is also a "pivot" feature in TSQL, however you do not have to use that feature to achieve the result. sometimes using case expressions and group by is just as easy - or even easier.

Hope this helps.

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
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for the help
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

From novice to tech pro — start learning today.