代码
select *
FROM
(select top 10 doccode,max(inserttime) as inserttime
from saletemplog
where companyid='A13'
and stcode='002'
and len(doccode)>30
group by doccode
) a
OUTER APPLY(
SELECT oldcode= STUFF(REPLACE(REPLACE(
(
SELECT oldcode FROM saletemplog
WHERE doccode = a.doccode
ORDER BY inserttime asc
FOR XML AUTO
), '<N oldcode="', ','), '"/>', ''), 1, 1, '')
) b
order by inserttime desc
FROM
(select top 10 doccode,max(inserttime) as inserttime
from saletemplog
where companyid='A13'
and stcode='002'
and len(doccode)>30
group by doccode
) a
OUTER APPLY(
SELECT oldcode= STUFF(REPLACE(REPLACE(
(
SELECT oldcode FROM saletemplog
WHERE doccode = a.doccode
ORDER BY inserttime asc
FOR XML AUTO
), '<N oldcode="', ','), '"/>', ''), 1, 1, '')
) b
order by inserttime desc