小弟有一数据库结构为A-B形式(A表为主表,是主销售表,B表是明细销售表)
A:销售编号(xbh),付款额(fke),实收金额(sje),找金额(zje)
030200,560.00,600.00,40.00
030201,430.00,450.00,20.00
B:销售编号(xbh),货品编号(hbh),单价(price),数量(sl),总金额(zje)
030200,200102,200.00,1,200.00
030200,200103,360.00,1,360.00
030201,200106,215.00,2,430.00
其中A-B表是靠销售编号来关联的,想分别取出A-B中相关的数据生成以下特定格式
的文本:
030200¦200102¦200.00¦¦1.00¦200.00
030200¦200103¦360.00¦¦1.00¦360.00
030200¦¦¦560.00¦600.00¦40.00
这个三行是由A-B表生成的一笔记录(第一两行是明细,第三行是总计)
我是想用两个数组S(),V(),将总表中030200的字段赋值给S(),将明细表
中是030200的字段赋值给V(),但我刚刚从foxpro转过来的,VB还不熟悉,不知
如何实现这个功能,请求各位大下指点,非常感激
A:销售编号(xbh),付款额(fke),实收金额(sje),找金额(zje)
030200,560.00,600.00,40.00
030201,430.00,450.00,20.00
B:销售编号(xbh),货品编号(hbh),单价(price),数量(sl),总金额(zje)
030200,200102,200.00,1,200.00
030200,200103,360.00,1,360.00
030201,200106,215.00,2,430.00
其中A-B表是靠销售编号来关联的,想分别取出A-B中相关的数据生成以下特定格式
的文本:
030200¦200102¦200.00¦¦1.00¦200.00
030200¦200103¦360.00¦¦1.00¦360.00
030200¦¦¦560.00¦600.00¦40.00
这个三行是由A-B表生成的一笔记录(第一两行是明细,第三行是总计)
我是想用两个数组S(),V(),将总表中030200的字段赋值给S(),将明细表
中是030200的字段赋值给V(),但我刚刚从foxpro转过来的,VB还不熟悉,不知
如何实现这个功能,请求各位大下指点,非常感激
insert into @a select '030200', 560.00, 600.00, 40.00
insert into @a select '030201', 430.00, 450.00, 20.00 declare @b table(xbh varchar(10),hbh varchar(10),price int,sl int,zje int)
insert into @b select '030200', 200102, 200.00, 1, 200.00
insert into @b select '030200', 200103, 360.00, 1, 360.00
insert into @b select '030201', 200106, 215.00, 2, 430.00
select *,1 as type from @b
union all
select xbh,null,fke,sje,zje,2 from @a
order by xbh,type
create table a(xbh varchar(10),fke int,sje int,zje int)
insert into a select '030200', 560.00, 600.00, 40.00
insert into a select '030201', 430.00, 450.00, 20.00 gocreate table b(xbh varchar(10),hbh varchar(10),price int,sl int,zje int)
insert into b select '030200', 200102, 200.00, 1, 200.00
insert into b select '030200', 200103, 360.00, 1, 360.00
insert into b select '030201', 200106, 215.00, 2, 430.00 EXEC master..xp_cmdshell 'bcp "select *,1 as type from b union all select xbh,null,fke,sje,zje,2 from a order by xbh,type" queryout c:\aa.txt -c -Syoki -Usa -P343132'
go
cn.Open "Provider=SQLOLEDB;Data Source=servername;User Id=sa;PassWord=;Initial Catalog=dbname"
cn.Execute "master..xp_cmdshell 'bcp ""select *,1 as type from b union all select xbh,null,fke,sje,zje,2 from a order by xbh,type"" queryout c:\aa.txt -c -Sservername -Usa -Ppassword'"
cn.Close
Set cn = Nothing