-1

入力:

      select(Emp_no, ADate, Atime)

      12333,     12-02-2013,    09.12 - 12.30
      12333,     12-02-2013,    12.32 - 17.30   

      13444,     12-02-2013,    09.10 - 18.30

      14444,     12-02-2013,    09.13 - 12.30
      14444,     12-02-2013,    17.20

出力:

      12333,     12-02-2013,    09.12 - 12.30 ; 12.32 - 17.30
      13444,     12-02-2013,    09.10 - 18.30
      14444,     12-02-2013,    09.13 - 12.30 ; 17.20
4

1 に答える 1

5

これに似たものを使用して、複数の行を1つの行に連結できます。

select distinct t1.Emp_no,
  t1.ADate, 
  STUFF(
         (SELECT '; ' + cast(t2.Atime as varchar(50))
          FROM yourtable t2
          where t1.Emp_no = t2.Emp_no
            and t1.ADate = t2.ADate
          FOR XML PATH (''))
          , 1, 1, '')  AS Atime
from yourtable t1

SQL FiddlewithDemoを参照してください

CROSS APPLYまたは、と一緒に使用できますFOR XML PATH

select distinct t1.Emp_no,
  t1.ADate, 
  left(t2.Atime, len(t2.atime)-1) ATime
from yourtable t1
cross apply
(
  select t2.Atime + '; '
  from yourtable t2
  where t1.Emp_no = t2.Emp_no
    and t1.ADate = t2.ADate
  FOR XML PATH('')
) t2 (Atime)

SQL FiddlewithDemoを参照してください

于 2013-02-19T13:58:53.607 に答える