--查询片区所有人 declare us cursor for (select MeterID,CCodeNO from MeterInfo m where m.CCodeNO=@code);
open us --打开游标
fetch next from us into @MeterID,@co --取下一条记录
while @@FETCH_STATUS=0 -- 循环查询所有人最后一条消费记录 begin --取出最后一记录,将值插入返回表中 insertinto @flow select top(1) MeterID,@co as code,TimeAccount from AccountFlow a where a.MeterID=@MeterID orderby a.TimeAccount desc