Nighil
Nighil

Reputation: 4127

can i use pivot for this?

this is the table structure

   id   empRef_ID   mkt_route_ID    sl_No
----------------------------------------------------
    1     8            6              1
    2     8            8              1
    3     8            20             2
    4     8            22             2
    5     8            23             2

and i want out put like this

    empRef_ID   mkt_route_ID    sl_No
----------------------------------------------------
      8            6/8            1
      8            20/22/23       2

Upvotes: 0

Views: 91

Answers (1)

Joe G Joseph
Joe G Joseph

Reputation: 24086

SELECT empRef_ID , mkt_route_ID=  
    STUFF((SELECT '/ ' + cast(mkt_route_ID as varchar)
           FROM table_2 b 
           WHERE b.sl_No = a.sl_No 
          FOR XML PATH('')), 1, 2, ''),sl_No 
FROM table_2 a
GROUP BY empRef_ID,sl_No

Upvotes: 4

Related Questions