Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to make columns to rows and vice versa in SQL

Posted on 2009-06-30
3
Medium Priority
?
327 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 1000 total points
ID: 24746108
0
 
LVL 17

Assisted Solution

by:pssandhu
pssandhu earned 1000 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

705 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