日期:2014-05-17  浏览次数:20839 次

ROW_NUMBER()转换问题,急!
如下语句请把
ROW_NUMBER() over(partition by fplx order by fpqsh) as rowid
转换一下,能在SQL2000里使用

create procedure fpkcqc
@startdate date ,--开始日期 
@enddate date --截止日期
as
truncate table rcgssfcbb
insert into rcgssfcbb (QCfplx,qcstart,qcend )
select fplx,
case when flag=1 or flag=3 then 剩余单据起始号+1 else 剩余单据起始号 end 剩余单据起始号,
case when flag=1 or flag=2 then 剩余单据结束号-1 else 剩余单据结束号 end 剩余单据结束号
from (
select a.fplx,a.fpjsh 剩余单据起始号,b.fpqsh 剩余单据结束号,1 as flag
from (select fplx,fpqsh,fpjsh,ROW_NUMBER() over(partition by fplx order by fpqsh) as rowid
from AA01_0005_E002 where AA01_0005_E001_PK IN (SELECT AA01_0005_E001_PK FROM AA01_0005_E001 WHERE dMakeDateEx <@startdate)) as a 
inner join 
(select fplx,fpqsh,fpjsh,ROW_NUMBER() over(partition by fplx order by fpqsh) as rowid
from AA01_0005_E002 WHERE AA01_0005_E001_PK IN (SELECT AA01_0005_E001_PK FROM AA01_0005_E001 WHERE dMakeDateEx <@startdate)) as b on a.rowid=b.rowid-1 and a.fplx=b.fplx 
union all
select fplx,fpqsh as 起始号,isnull((select MIN(fpqsh) from AA01_0005_E002 where fplx=a.fplx),a.fpjsh) 结束号,
case when (select MIN(fpqsh) from AA01_0005_E002 where AA01_0005_E001_PK IN (SELECT AA01_0005_E001_PK FROM AA01_0005_E001 WHERE dMakeDateEx <@startdate) AND fplx=a.fplx) IS null then 4 else 2 end as flag
from (select * from AA01_0004_E002 where AA01_0004_E001_PK in (select AA01_0004_E001_PK from AA01_0004_E001 where dMakeDateEx <@startdate)) as a 
union all
select fplx,(select max(fpjsh) from AA01_0005_E002 where AA01_0005_E001_PK IN (SELECT AA01_0005_E001_PK FROM AA01_0005_E001 WHERE dMakeDateEx <@startdate) AND fplx=a.fplx ),fpjsh,3 as flag
from (select * from AA01_0004_E002 where AA01_0004_E001_PK in (select AA01_0004_E001_PK from AA01_0004_E001 where dMakeDateEx <@startdate)) as a 
) as X


好像能这样:
rowid=(select count(1) from AA01_0006_E002 where fplx=t.fplx and fpqsh<=t.fpqsh) from AA01_0006_E002 t

------解决方案--------------------
 row_number = IDENTITY(int,1,1)+ order by 
 
 具体你转下 看这SQL 密密麻麻
------解决方案--------------------
给lz举个例子吧
if OBJECT_ID('t') is not null drop table t
go

create table t
(
id int,