Solved

How to make columns to rows and vice versa in SQL

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
In this article I will describe the Backup & Restore 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.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

22 Experts available now in Live!

Get 1:1 Help Now