Solved

How to make columns to rows and vice versa in SQL

Posted on 2009-06-30
3
324 Views
Last Modified: 2012-05-07
I'm trying to change the structure in my query so that the columns will results as rows and vice versa. Is this possible in any way?
SELECT column1,column2,column3
FROM         Table
WHERE     (column2 = 'value')
GROUP BY column1,column2,column3

Open in new window

0
Comment
Question by:gosi75
[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
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 24746108
0
 
LVL 17

Assisted Solution

by:pssandhu
pssandhu earned 250 total points
ID: 24746123
Check the pivot and unpivot functions for SQL Server 2005. I cannot give you an example with the data you provided since I need to see the data.
But in any case you learn about it here: http://msdn.microsoft.com/en-us/library/ms177410.aspx
P.
0
 

Author Comment

by:gosi75
ID: 24746294
I have been looking into using PIVOT but did ran into some problems there.

Here is the code I want to make a pivot, is it possible to do it with the query?


SELECT DISTINCT 
                      l.ls_letterid,  
                      m.ls_strength, m.ls_unitidname, m.ls_name, p.ls_package_name
FROM         FilteredLS_letter AS l INNER JOIN
                      FilteredLS_project AS v ON l.ls_projectid = v.ls_projectid INNER JOIN
                      Filteredls_project_medicinal_product AS vm ON v.ls_projectid = vm.ls_projectid INNER JOIN
                      FilteredLS_MEDICINAL_PRODUCT AS m ON vm.ls_medicinal_productid = m.ls_medicinal_productid INNER JOIN
                      FilteredAccount AS a ON m.ls_marketingauthorisationholderid = a.accountid INNER JOIN
                      FilteredLS_Package AS p ON m.ls_medicinal_productid = p.ls_medicinalproductid
WHERE     (l.ls_letterid = '540180EA-2F49-DE11-AC68-0050568C7C98')
GROUP BY m.ls_name, p.ls_package_name, l.ls_letterid,  m.ls_unitidname

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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