Solved

How to make columns to rows and vice versa in SQL

Posted on 2009-06-30
3
319 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
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

17 Experts available now in Live!

Get 1:1 Help Now