日期:2014-05-17 浏览次数:20586 次
--a. 记录表,b.明细表
create table #t(编号 int,客户名称 varchar(20),电话 varchar(20),产品型号 varchar(20),价格 int)
insert into #t 
select 编号,客户名称,电话,'设计费',设计费 from a where 设计费<>0 union all
select 编号,客户名称,电话,'安装费',安装费 from a where 安装费<>0union all
select 编号,客户名称,电话,'优惠', 0-优惠 from a where 优惠<>0
select * from #t union all 
select a.编号,客户名称,电话,产品型号,价格 from a,b where a.编号=b.编号
drop table #t
----------------------------------------
编号          客户名称                 电话                   产品型号                 价格
----------- -------------------- -------------------- -------------------- ---------------------
23          客户3                  135677666            设计费                  3000.00
25          客户4                  1844554645           设计费                  3800.00
20          客户1                  15938393             安装费                  200.00
25          客户4                  1844554645           安装费                  2400.00
23          客户3                  135677666            优惠                   -1000.00
20          客户1                  15938393             C9080W               270.00
20          客户1                  15938393             9080W                660.00
22          客户2                  138055555            A8091W               30.00
23          客户3                  135677666            C7000W               80.00
25          客户4                  1844554645           C3102W               12.00
(10 行受影响)