Solved

T-SQL Translate data

Posted on 2008-10-27
4
418 Views
Last Modified: 2012-05-05
Hi,  How can I translate data from a table to show up in a query in this manner:
Data  in table is like this:
Ed, 3
Ed, 2
Ed, 1
Ed, 4
Bob, 3
Bob, 2
Bob, 1
Bob, 4

output query to look like this:

Ed, 1, 2, 3, 5
Bob, 1, 2, 3, 4

Any help much appreciated.

Thanks.
0
Comment
Question by:sublimation
  • 2
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22811066
please see this article for the implementation of a function to do that (the 1,2,3,4 going into 1 column!)
http://anthony-yio.blogspot.com/2007/12/mssql-groupconcat.html

the alternative (for sql 2000, for example) would be a dedicated function:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=33574
0
 
LVL 4

Author Comment

by:sublimation
ID: 22812340
Hi,

The 1,2,3,4 goes into 4 separate columns.  The example reference is not very clear.  was hoping for some sql code/pseudo code.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22812500
you will have to specify more, especially as you want several columns output.
please clarify a bit more about the input/output.
0
 
LVL 4

Accepted Solution

by:
sublimation earned 0 total points
ID: 22819767
Hi, Angel.

I have found a solution now thanks.  The column names do not matter, you can see a clear example of translation.  We can call the columns col1, col2, col3, just as long as the data is translated in the manner shown.

The way to do it was to create a join on the same table numerous times (for each column required).

Thanks for your help
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 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

20 Experts available now in Live!

Get 1:1 Help Now