select 0 排号,计量性质,发货单位,物质名称 into #临时表 from 你的表 order by 计量性质,物质名称
declare @a int,@b varchar(100),@c varchar(100)
update #临时表 set @a=case when 计量性质=@b and 物质名称=@c then @a when 计量性质=@b and 物质名称<>@c then @a+1 else 1 end,@b=计量性质,@c=物质名称,排号=@aselect * from #临时表
go
drop table #临时表
declare @a int,@b varchar(100),@c varchar(100)
update #临时表 set @a=case when 计量性质=@b and 物质名称=@c then @a when 计量性质=@b and 物质名称<>@c then @a+1 else 1 end,@b=计量性质,@c=物质名称,排号=@aselect * from #临时表
go
drop table #临时表
as
set nocount on
select 0 排号,计量性质,发货单位,物质名称 into #临时表 from 你的表 order by 计量性质,物质名称
declare @a int,@b varchar(100),@c varchar(100)
update #临时表 set @a=case when 计量性质=@b and 物质名称=@c then @a when 计量性质=@b and 物质名称<>@c then @a+1 else 1 end,@b=计量性质,@c=物质名称,排号=@a
select * from #临时表
set nocount off
go
然后调用就行了:
exec p_show