Link to home
Start Free TrialLog in
Avatar of gosi75
gosi75Flag for Iceland

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gosi75

ASKER

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