分段更新数据
--SELECT stuid FROM dbo.BZList WHERE AreaOrganID=-1 AND AreaPointCode=-1 AND DeptOrganID=-1
SELECT bzid,stuid, BZKTypeID, BZKTypeName, BZDate, BZData, BZRemark, PointCode FROM dbo.BZList WHERE StuID =338180 ORDER BY BZDate
SELECT bzid,stuid, BZKTypeID, BZKTypeName, BZDate, BZData, BZRemark, PointCode FROM dbo.BZList WHERE StuID =338180 AND BZKTypeCode=202 ORDER BY BZDate
WITH rs
AS ( SELECT stuid AS n
FROM dbo.BZList
WHERE AreaOrganID = -1
AND AreaPointCode = -1
AND DeptOrganID = -1
)
SELECT
bzid,stuid, BZKTypeID, BZKTypeName, BZDate, BZData, BZRemark, PointCode,
ISNULL(( SELECT TOP 1
BZRemark
FROM dbo.BZList b2
WHERE b1.stuid=b2.stuid
AND BZKTypeName = '转学'
AND b2.BZDate > b1.BZDate
), b1.PointCode)
FROM dbo.BZList b1
WHERE EXISTS ( SELECT TOP 1 1 FROM rs WHERE n = StuID )
ORDER BY stuid,b1.BZDate