用sql脚本 为每一个单据,依次 跟正 行号 现有表如下 if exists(select *from sysobjects where name ='aa' and xtype='u') drop table aa create table aa (日期 varchar(20),单据号 int,单据行号 int) insert into aa select '200801' , 22 ,'1' union all select '200801' , 22 ,'1' union all select '200801' , 23 ,'1' union all select '200801' , 23 ,'1' union all select '200801' , 23 ,'1' union all select '200801' , 28 ,'1' union all select '200801' , 28 ,'1' union all select '200801' , 28 ,'1' union all select '200801' , 28 ,'1' union all select '200801' , 28 ,'1' union all select '200801' , 28 ,'1' union all select '200801' , 28 ,'1' union all select '200801' , 28 ,'1' union all select '200801' , 28 ,'1' union all select '200801' , 29 ,'1' union all select '200801' , 29 ,'1' union all select '200801' , 30 ,'1' union all select '200801' , 30 ,'1' union all select '200801' , 30 ,'1' union all select '200801' , 31 ,'1' union all select '200801' , 31 ,'1' union all select '200801' , 31 ,'1' union all select '200801' , 31 ,'1' select * from aa
--为每一个单据,依次 跟正 行号, ---用sql脚本 使其出现如下结果
select '200801' , 22 ,'1' union all select '200801' , 22 ,'2' union all select '200801' , 23 ,'1' union all select '200801' , 23 ,'2' union all select '200801' , 23 ,'3' union all select '200801' , 28 ,'1' union all select '200801' , 28 ,'2' union all select '200801' , 28 ,'3' union all select '200801' , 28 ,'4' union all select '200801' , 28 ,'5' union all select '200801' , 28 ,'6' union all select '200801' , 28 ,'7' union all select '200801' , 28 ,'8' union all select '200801' , 28 ,'9' union all select '200801' , 29 ,'1' union all select '200801' , 29 ,'2' union all select '200801' , 30 ,'1' union all select '200801' , 30 ,'2' union all select '200801' , 30 ,'3' union all select '200801' , 31 ,'1' union all select '200801' , 31 ,'2' union all select '200801' , 31 ,'3' union all select '200801' , 31 ,'4'