Output
values as single line CSV
declare
@yourtable table
([ID]
int, [Date] datetime)
;
INSERT INTO
@yourtable
([ID],
[Date])
VALUES
(756,
'2011-08-29 00:00:00'),
(756,
'2011-08-31 00:00:00'),
(756,
'2011-09-01 00:00:00'),
(756,
'2011-09-02 00:00:00')
;
INSERT INTO
@yourtable
([ID],
[Date])
VALUES
(956,
'2011-08-29 00:00:00'),
(956,
'2011-08-31 00:00:00'),
(956,
'2011-09-01 00:00:00'),
(956,
'2011-09-02 00:00:00')
;
-- example
1-----------------------------------------------------------------
select
distinct
t1.id,
STUFF((SELECT
', ' + convert(varchar(10), t2.date, 120)
FROM @yourtable t2
where t1.id = t2.id
FOR XML PATH ('')), 1, 1, ''
) AS date
from @yourtable t1;
No comments:
Post a Comment