Winston Madiano Winston Madiano - 20 days ago 6
SQL Question

How To Convert Rows Into Column In Single Select Query SQL Server 2008 R2

How to return the following result on single select query.

Table

Rn TicketNo CreateDate Assigned
1 xxx 2016-11-17 03:45:46.000 Tom
2 xxx 2016-11-18 03:45:46.000 Jerry
1 yyy 2016-11-17 03:45:46.000 Tom
2 yyy 2016-11-18 03:45:46.000 Jerry


Expected Result

TicketNo AssignedToTom AssignedToJerry
xxx 2016-11-17 03:45:46.000 2016-11-18 03:45:46.000
yyy 2016-11-17 03:45:46.000 2016-11-18 03:45:46.000


Many thanks in advance

Answer

Try This: replace with name of your table

select a.ticketno
        ,a.CreateDate as [AssignedToTom]
        ,b.CreateDate as [AssignedToJerry]
         from <tablename> a join <tablename> b 
         on a.assigned='Tom' and b.assigned='Jerry' 
         and a.ticketno=b.ticketno