Solved

T-SQL Translate data

Posted on 2008-10-27
4
431 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
[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
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Formating field in mysql Advance formatting 1 52
SQL Select Query help 1 48
SQL Server how to create a DYNAMIC TABLE? 11 50
Queries: Select, then Append, then Delete 8 38
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

737 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