Solved

sql data formatting scenario

Posted on 2014-10-21
3
73 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
  • 2
3 Comments
 
LVL 46

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 46

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query 3 49
Insert Salary Period that has 2 months 11 23
Benefits of SMB Fileshare 3 63
Ssis not sending failure message 2 10
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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now