order                        ship
id,rdsno                     id,rdsno 
1   SO05060001                1  SE05060012
2   SO05060002                2  SE05060013orderprod                    shiplst
id,zbid,code,sendnumb        id,zbid,code,sendnumb,senddate,  pid
1   1    Prod1  2000          1   1   Prod1  1000  2006-05-12  1
1   2    Prod2  2500          1   2   Prod1  1000  2006-05-13  1
                              2   2   Prod2  2500  2006-05-13  2

解决方案 »

  1.   

    order                                              id,rdsno                                          
    1      SO05060001                                
    2      SO05060002                                
     
    orderprod                                       
    id,zbid,code,sendnumb                
    1      1        Prod1    2000                         
    1      2        Prod2    2500    ship  
    id,rdsno
    1    SE05060012                      
    2    SE05060013   shiplst           
    id,zbid,code,sendnumb,senddate,    pid   
    1   2   Prod1   1000  2006-05-13    1            
    1   1   Prod1   1000  2006-05-12    1 
    2   2   Prod2   2500   2006-05-13   2 
    就是此四表
      

  2.   

    要的结果是
    order.rdsno,code,  送货数合并的字符串
    SO05060001,Prod1,1000/2006-05-12/1000/2006-05-13
    SO05060002,Prod2,2500/2006-05-13
      

  3.   

    create table a(id int,rdsno varchar(20))
    insert into a select 1,'SO05060001'                           
    union all select 2,'SO05060002'create table b(id int,zbid int,code varchar(10),sendnumb int)
    insert into b select 1,1,'Prod1',2000                         
    union all select 1,2,'Prod2',2500create table c(id int,rdsno varchar(20))
    insert into c select 1,'SE05060012'                     
    union all select 2,'SE05060013'create table d(id int,zbid int,code varchar(10),sendnumb int,senddate varchar(10),pid int)
    insert into d select 1,2,'Prod1',1000,'2006-05-13',1            
    union all select 1,1,'Prod1',1000,'2006-05-12',1 
    union all select 2,2,'Prod2',2500,'2006-05-13',2
    gocreate function dbo.fc_str(@id int)
    returns varchar(100)
    as
    begin
     declare @sql varchar(1000)
     set @sql=''
     select @sql=@sql+'/'+cast(sendnumb as varchar)+'/'+cast(senddate as varchar) from d where id=@id
     return stuff(@sql,1,1,'')
    end
    goselect a.rdsno,d.code,dbo.fc_str(a.id) from a,d where a.id=d.id group by a.rdsno,d.code,a.iddrop table a,b,c,d
    drop function dbo.fc_str
      

  4.   

    xeqtr1982(HaN)寫出來了,俺就不貼上去了。的確有兩個表沒用。另外,關聯字段有點模糊,不知道是id還是pid。
      

  5.   

    送货单明细是通过产品编号和订单产品中的产品编号,PID和订单产品的ID关联,送货单明细(orderno)和订单的编号(rdsno)关联,订单表ID和订单产品表ZBID关联,送货表ID和送货单产品的ZBID关联
      

  6.   

    --调整了一下关联,楼主可以自己调整一下
    create table a(id int,rdsno varchar(20))
    insert into a select 1,'SO05060001'                           
    union all select 2,'SO05060002'create table b(id int,zbid int,code varchar(10),sendnumb int)
    insert into b select 1,1,'Prod1',2000                         
    union all select 1,2,'Prod2',2500create table c(id int,rdsno varchar(20))
    insert into c select 1,'SE05060012'                     
    union all select 2,'SE05060013'create table d(id int,zbid int,code varchar(10),sendnumb int,senddate varchar(10),pid int)
    insert into d select 1,2,'Prod1',1000,'2006-05-13',1            
    union all select 1,1,'Prod1',1000,'2006-05-12',1 
    union all select 2,2,'Prod2',2500,'2006-05-13',2
    gocreate function dbo.fc_str(@pid int)
    returns varchar(100)
    as
    begin
     declare @sql varchar(1000)
     set @sql=''
     select @sql=@sql+'/'+cast(sendnumb as varchar)+'/'+cast(senddate as varchar) from d where pid=@pid
     return stuff(@sql,1,1,'')
    end
    goselect a.rdsno,d.code,dbo.fc_str(d.pid) from a,d where a.id=d.pid group by a.rdsno,d.code,d.piddrop table a,b,c,d
    drop function dbo.fc_str
      

  7.   

    解决了,谢谢xeqtr1982(HaN)的帮助。