--表结构(BH=票号,XS=销售,LP=联票)
--PBH为上1个票号,NPH为下1个票号,int
--SQL2000测试通过,计算出那些是联票
--create table #tmp(bh int,xs varchar(2))
--GO
--insert into #tmp(bh,xs) values(10001,'否')
--insert into #tmp(bh,xs) values(10002,'否')
--insert into #tmp(bh,xs) values(10003,'否')
--insert into #tmp(bh,xs) values(10004,'否')
--insert into #tmp(bh,xs) values(10005,'否')
--insert into #tmp(bh,xs) values(10006,'是')
--insert into #tmp(bh,xs) values(10007,'否')
--insert into #tmp(bh,xs) values(10008,'否')
--Insert into #tmp(bh,xs) values(10009,'否')
--Insert into #tmp(bh,xs) values(10010,'否')
--Insert into #tmp(bh,xs) values(10011,'否')
update #tmp set xs='否' where bh=10002 --改变某个BH的XS值,测试结果
select d.*,(case when xs='否' and(nxs='否' or pxs='否') then '联' else '否' end) as lp from
(select a.pbh,a.bh,a.xs,a.nbh,b.xs as nxs,c.xs as pxs from
(select bh-1 as pbh,bh,xs,bh+1 as nbh from #tmp)a
left join (select * from #tmp)b on a.nbh=b.bh
left join (select * from #tmp)c on a.pbh=c.bh)d
图片附件: 游客没有浏览图片的权限,请
登录 或
注册