create table table1 (devicename varchar(10)
,name varchar(100)
,value varchar(10)
,TimeSTamp datetime)
INSERT INTO table1
SELECT '123','CURRENT','130','2012-10-16 13:00:00.000'
UNION
SELECT '123','AVG','140','2012-10-16 13:00:00.000'
UNION
SELECT '123','MIN','100','2012-10-16 13:00:00.000'
UNION
SELECT '123','MAX','160','2012-10-16 13:00:00.000'
select devicename, name, value, timestamp from table1
SELECT DISTINCT t1.devicename
, value_list
, t1.timestamp
FROM table1 t1
INNER JOIN (SELECT t2.devicename
, t2.timestamp
, value_list = SUBSTRING((SELECT t3.value
+ ', '
FROM table1 t3
WHERE t3.devicename = t2.devicename
AND t3.timestamp = t2.timestamp
ORDER BY t3.value
FOR XML PATH('')),1,LEN((SELECT t3.value
+ ', '
FROM table1 t3
WHERE t3.devicename = t2.devicename
AND t3.timestamp = t2.timestamp
ORDER BY t3.value
FOR XML PATH(''))) -1)
FROM table1 t2
GROUP BY t2.devicename
, t2.timestamp) t4 on t4.devicename = t1.devicename
AND t4.timestamp = t1.timestamp
drop table1