Link to home
Start Free TrialLog in
Avatar of codeoxygen
codeoxygen

asked on

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

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
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

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.
Avatar of codeoxygen
codeoxygen

ASKER

Vitor sir  i used it but it shows error  so please how to use it can u explain
Can you post your actual query and the error returned?
vitor sir above i designed the expected result  ,that result query i need can u  write the code
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.
Table structure and data are given in file. Please find attachment
Query.sql
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'.
table structure and data are given in file .please find attachment
Query.sql
Query.sql
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland 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