0

Table values:

EMP_NO EMP_NAME                     
-------------- 
    14 admin                          
     1 ram                            
     2 mohan                          
     3 mallu                          
     4 scoot                          
     5 jim                            
     6 ravi                           
     7 manju                          
     8 manoj                          
     9 sarath                         
    10 hemanth                        

how to convert rows to columns?

Noel
  • 10,152
  • 30
  • 45
  • 67
ram12393
  • 1,284
  • 3
  • 14
  • 29

1 Answers1

0

try following query for oracle

select 
   emp_no,
   rtrim (xmlagg (xmlelement (e, emp_name || ',')).extract ('//text()'), ',') enames
from 
   emp
group by 
   emp_no
;

for sql server try

SELECT *
FROM (
    SELECT 
       emp_name 
    FROM tblemployee
) as s
PIVOT
(
    min(emp_id)
    FOR emp_id
)AS pivot
Indranil.Bharambe
  • 1,462
  • 3
  • 14
  • 25