Hello everyone, I have a table with the description as shown below:
But, I want to display the result like this:

Can someone teach me how to do it? thanks in advance
Hello everyone, I have a table with the description as shown below:
But, I want to display the result like this:

Can someone teach me how to do it? thanks in advance
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vishal JoshiPosted Feb 14, 2023, 7:05 AM
Hello,
Please try the below optimized query to get same result.it will make only single call to table. we can use SUM and CASE.
Thanks
Jignesh KumarPosted Feb 14, 2023, 7:04 AM
Hello Hold On,
You can use Pivot to acheve this one,
https://www.c-sharpcorner.com/UploadFile/suthish_nair/convert-rows-to-columns-in-sql-server-20082005/
https://stackoverflow.com/questions/15745042/efficiently-convert-rows-to-columns-in-sql-server
Manikandan RPosted Feb 14, 2023, 6:47 AM
Hello
Small Try,
Jes SiePosted Feb 14, 2023, 6:46 AM
Hi Naimish, thanks for your reply. Your solution will give me a vertical result. What I wanted is a horizontal result. So, below is what I did
The above-mentioned query gives me the result that I wanted. However, if there is a simpler way to do it, I need to try.
Naimish MakwanaPosted Feb 14, 2023, 6:40 AM
Hello,
You can use UNION operator.
Example :
Thanks