insert into plm_quote_detail_tool
(quote_detail_id, quote_id, quote_no, site, bu_no, version_no, quote_detail_item_no, tool_no, item_no, tool_desc, tool_qty, tool_spec, unit_cost, expected_service_life, quote_unit_cost, remark, create_by, create_date, update_by, update_date)
select
#{quoteDetailId},
#{quoteId},
#{quoteNo},
#{site},
#{buNo},
#{versionNo},
#{quoteDetailItemNo},
'',
row_number() over (ORDER BY rt.id),
th.tool_description,
rt.tool_qty,
'',
isnull(th.standard_cost,0),
0,
case when rt.tool_qty = 0 then 0 else th.standard_cost / rt.tool_qty end,
null,
#{createBy},
#{createDate},
null,
null
from routing_tool rt
left join tool_header th on rt.tool_id = th.tool_id and rt.site = th.site
where rt.site = #{site}
and rt.part_no = #{partNo}
and rt.routing_revision = #{routingRevision}
and rt.routing_type = #{routingType}
and rt.alternative_no = #{alternativeNo}