select *
into [DataTable] --[DataTable]为你想要储存数据的表名。直接插入就可以了,自动创建这个表的
from (select distinct [SellID] FROM Query) A OUTER
APPLY(
SELECT [ID]=STUFF(REPLACE(REPLACE(
(
SELECT [BookID] FROM Query N
where SellID=A.SellID
FOR XML AUTO
),'
)N
ORDER by [SellID]