Solved

How to make columns to rows and vice versa in SQL

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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