SQL server code (UPDATE)
i ha开发者_运维知识库ve a problem of how to update data from table A to table B and make in horizontal from vertical..example is
Table A ----------- Table B
ID ----- Item ----------- ID ------Item
11--- iPhone4 ----------- 11 ------iPhone4,iPhone4s,iPhone5
11--- iPhone4s
11--- iPhone5
mean that from 3 Rows become 1 rows. Please help,really noob in this case.. Thanks
Try with this..
Select ID,
Left(Item,Len(Item)-1) As Items
From(
Select distinct T2.ID,
(Select
T1.Item + ',' AS [text()]
From TableA T1
where T1.ID = T2.ID
For XML PATH ('')) [item]
From dbo.TableA T2
) t
Try this..Use GROUP_CONCAT to merge in one row the rows you want to merge.
SELECT ID,GROUP_CONCAT(item)
FROM yourtable
GROUP BY ID;
精彩评论