使用存储过程取数据的时候,经常会碰到多表连接的问题,这种时候千万不要在insert的时候就实用join,不然数据量一大,运行效率就很成问题,如下:
insert into #temp(order_no,order_type,order_line_no,sku_no,part_no,pr_description,order_qty,unit_price)
select
order_no,order_type,order_line_no,t.sku_no,tt.part_no,tt.short_desc,order_qty,unit_price
from CIS..order_detail t
inner join CIS..part_master tt on t.sku_no = tt.sku_no
where order_no=@order_no and order_type=@order_type
这样运行效率是很低的
最好是insert和join分开,先insert完以后,用update来join更好些
insert into #temp(order_no,order_type,order_line_no,sku_no,order_qty,unit_price) select
order_no,order_type,order_line_no,sku_no,order_qty,unit_price from CIS..order_detail
where order_no=@order_no and order_type=@order_type
update #temp set a.part_no= b.part_no,
a.description= b.short_desc
from #temp a
inner join CIS..part_master b
on a.sku_no=b.sku_no