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
  • 8,638
  • 28
  • 44
  • 63
ram12393
  • 1,088
  • 2
  • 13
  • 25

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,442
  • 3
  • 14
  • 25