Solved

sql data formatting scenario

Posted on 2014-10-21
3
95 Views
Last Modified: 2014-12-03
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
Comment
Question by:royjayd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 51

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40394503
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
 

Author Comment

by:royjayd
ID: 40394689
>>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
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40394786
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question