Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Convert columns to rows in SQL

Hello Experts,
I have a column based table of million of rows.  I am trying to convert the columns to rows for better readability.  See the attachment for details.  Please let me know how to get the output.  Thank you very much in advance.

Thank you!
Pivot.png
ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan R
Raja Jegan R
Flag of India 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
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Hello Raja, Thank you for your quick response.  I ran your query and received the output as below.

CID          1      2      3
10001   null  null  null

More over the FN-1, FN-2, FN-3 are the descriptions.  But, I received just the numbers.
Kindly check whether the below query returns values and if so, then you should get proper records for the first query provided..
SELECT CID, FNAME, FV
FROM table1 
JOIN table2 on table1.FID = table2.FID

Open in new window

Raja, Thank you very much.  Your code is working as expected.  There was some error in my typing.  Thank you again.
Welcome, no issues..
Raju,
Can I use the fields [FN-1], [FN-2], [FN-3] ect. with where clause to filter some rows?  If so, how?  When I use it,, I get "Invalid column name FN-1" error.

Thank you a lot.
Yes, we can use these columns in WHERE clause.
Since you have - inside, just use [FN-1] which might help..
I already tried that and got "Invalid column name FN-1" error.  Any different way to use it?
Can you provide your complete query to help out with..