How convert each row of table to as columns in sql server

codeoxygen
codeoxygen used Ask the Experts™
on
hi,
      I want convert entire row in table as single column , example is show below

QuteNo     || requestNo  ||      cat1    || cat2    || cat3
------------------------------------------------------------------------------------
01                            1                        a               b               c
2                               1                        d               e               f
3                                2                       g                  k              l

Expected Result :

 heading          01    2    3
requestno        1      1    2
  cat1                 a       d     g
  cat2                 b       e    k
    cat3               c         f    i
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
You'll need to use PIVOT but usually you'll need to know the field values otherwise you'll need to do it dynamically that it's more complex.

Author

Commented:
Vitor sir  i used it but it shows error  so please how to use it can u explain
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
Can you post your actual query and the error returned?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
vitor sir above i designed the expected result  ,that result query i need can u  write the code
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
If you post your code and the error I'll be happy to show you how and where to change it so it can work.

Author

Commented:
Table structure and data are given in file. Please find attachment
Query.sql
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
You query returns error:
Msg 207, Level 16, State 1, Line 73
Invalid column name 'Insuranceprovider'.
Msg 207, Level 16, State 1, Line 74
Invalid column name 'Insurancetype'.

Author

Commented:

Author

Commented:
table structure and data are given in file .please find attachment
Query.sql
Query.sql
IT Engineer
Distinguished Expert 2017
Commented:
I'm sorry but I just missed your last comments.
Do you still need help with this?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial