<?xml version="1.0" encoding="utf-8" ?>
<select>
  <selectstr>
SELECT mtrlid
	,mtrltype
	,name
	,priceunit
	,price
	,gram_weight
	,cloth_width
	,if_inputqty
	,if_areaprice
	,createtime
	,createby
	,pricelistprice
	,thickness
	,dscrp
	,erp_mtrlid
	,erp_mtrlcode
	,erp_mtrlname
	,erp_mtrlmode
	,erp_unit
	,erp_mtrlengname
	,fjcnt
	,isuse
	,lastdate
	,handtype
	,pricelistid
FROM (
	SELECT u_mtrl_price.mtrlid
		,u_mtrl_price.mtrltype
		,u_mtrl_price.name
		,u_mtrl_price.priceunit
		,u_mtrl_price.shrinkage AS price
		,u_mtrl_price.gram_weight
		,u_mtrl_price.cloth_width
		,u_mtrl_price.if_inputqty
		,u_mtrl_price.if_areaprice
		,u_mtrl_price.createtime
		,u_mtrl_price.createby
		,isnull(u_mtrl_price_pricelist.price, 0) AS pricelistprice
		,u_mtrl_price.thickness
		,u_mtrl_price.dscrp
		,erp_mtrlid
		,Space(200) AS erp_mtrlcode
		,Space(200) AS erp_mtrlname
		,Space(200) AS erp_mtrlmode
		,Space(200) AS erp_unit
		,Space(200) AS erp_mtrlengname
		,u_mtrl_price.fjcnt AS fjcnt
		,u_mtrl_price.isuse AS isuse
		,u_mtrl_price.lastdate AS lastdate
		,u_mtrl_price.handtype AS handtype
		,u_mtrl_price_pricelist.pricelistid
	FROM u_mtrl_price
	INNER JOIN u_mtrl_price_pricelist ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
	WHERE (u_mtrl_price_pricelist.pricelistid = @pricelistid)
	
	UNION ALL
	
	SELECT u_mtrl_price.mtrlid
		,u_mtrl_price.mtrltype
		,u_mtrl_price.name
		,u_mtrl_price.priceunit
		,u_mtrl_price.shrinkage AS price
		,u_mtrl_price.gram_weight
		,u_mtrl_price.cloth_width
		,u_mtrl_price.if_inputqty
		,u_mtrl_price.if_areaprice
		,u_mtrl_price.createtime
		,u_mtrl_price.createby
		,0 AS pricelistprice
		,u_mtrl_price.thickness
		,u_mtrl_price.dscrp
		,erp_mtrlid
		,Space(200) AS erp_mtrlcode
		,Space(200) AS erp_mtrlname
		,Space(200) AS erp_mtrlmode
		,Space(200) AS erp_unit
		,Space(200) AS erp_mtrlengname
		,u_mtrl_price.fjcnt AS fjcnt
		,u_mtrl_price.isuse AS isuse
		,u_mtrl_price.lastdate AS lastdate
		,u_mtrl_price.handtype AS handtype
		,0 AS pricelistid
	FROM u_mtrl_price
	WHERE (
			u_mtrl_price.mtrlid NOT IN (
				SELECT mtrlid
				FROM u_mtrl_price_pricelist
				WHERE pricelistid = @pricelistid
				)
			)
	) v_mtrl_price
  </selectstr>
  <where>
	<when notnull="@@mtrltypeids@@">
		v_mtrl_price.mtrltype IN (@@mtrltypeids@@)
	</when>
  </where>
  <displayfields>
    <field field="pid" compute="getrow()">序</field>
    <field field="fjcnt">附件</field>
    <field field="name">名称</field>
    <field field="pricelistprice" datatype="number">单价</field>
    <field field="priceunit">单位</field>
    <field field="price" datatype="number">收缩率</field>
    <field field="thickness" datatype="number">厚度</field>
    <field field="gram_weight" datatype="number">克重</field>
    <field field="if_inputqty" datatype="checkbox">固定厚度？</field>
    <field field="if_areaprice" datatype="checkbox">单价按面积？</field>
    <field field="dscrp">备注</field>
    <field field="createby">登记人</field>
    <field field="createtime" datatype="datetime">登记时间</field>
    <field field="erp_mtrlcode">L1物料编码</field>
    <field field="erp_mtrlname">L1物料名称</field>
    <field field="erp_mtrlmode">L1物料规格</field>
    <field field="erp_unit">L1物料单位</field>
    <field field="erp_mtrlengname">L1英文名称</field>
    <field field="mtrlid">核价Mtrlid</field>
    <field field="isuse" datatype="checkbox">有效</field>
    <field field="lastdate" datatype="date">有效时间</field>
    <field field="handtype" mapper="mtrltypeid">默认类别</field>
	<field field="pricelistid" mapper="">价格表</field>
  </displayfields>
</select>
