Solved

T-SQL Translate data

Posted on 2008-10-27
4
427 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 143

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 143

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql server insert 12 40
Present Absent from working date rage 11 37
table joins in qry 17 61
Using SQL*PLUS issue with where statement with trunc function 3 29
'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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 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