Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

How to make columns to rows and vice versa in SQL

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
gosi75
Asked:
gosi75
2 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
0
 
pssandhuCommented:
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
 
gosi75Author Commented:
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now