Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 102
  • Last Modified:

sql data formatting scenario

hi experts
when i query my table
select Product, Name, Value, Yearly_Amount from Customer_Research
The data i get is something like this
Data from my table
So if you see there are three products MBS,OOK,ZRR. The Name,Value,Yearly_Amount are same for all these products which is
TOM Adjust      60      2772
MAC Inc             20      10406438
SDRF             58      2764
PPLED             89      1

What i am trying to do is to get a result set like this ...    
trying to show / group by multiple column values
So basically trying to group by Name/Value/Yearly_Amount entries and see the products
But that might not be the best way to represent the data, maybe a little confusing to the user perhaps?

This representation woud be best i think
comma seperated grouping
Is it possible to do what i am trying to do?
Any sugessions would be greatly appreciated.
Thanks.
2.png
2.png
2.png
0
royjayd
Asked:
royjayd
  • 2
1 Solution
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
It looks like you are facing a bad database model design. How can you have a table with repeated values like that?

Instead of giving you a solution for a query, I think it's better to help you to get a normalized database model.
Can you post your table structure and the query that you are using?
Also if it's possible to know how you are insert data in that table (how and where's the data coming from)?
0
 
royjaydAuthor Commented:
>>How can you have a table with repeated values like that?

We do have a normalized database model.
That was just a sample sql, i dint want to post the entire query since it contains INNER JOINS on more than 5 tables[The query itself is pretty big]
 I was focussing more on the result set and how to tweak the result set if possible.

Thanks.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
It will be very hard to work with a subset of the data and only with a small part of the query.
I will then suggest you to study the STUFF function together with FOR XML PATH option, since can be what you are looking for. Check the example #6 in this article.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now