<?xml version="1.0" encoding="utf-8" ?>
<select>
	<selectstr>
		SELECT
			u_mattress.mattressid,
			mattresscode,
			mattress_width,
			mattress_length,
			mattress_height,
			parentid,
			ISNULL(vv_mattress.mtrlid, 0) AS mtrlid,
			ISNULL(u_bednetmx.spring_qty_width, 0) AS spring_qty_width,
			ISNULL(u_bednetmx.spring_qty_length, 0) AS spring_qty_length,
			u_mattress.erp_mtrlid,
			u_mattress.erp_mtrlcode
		FROM u_mattress
		LEFT OUTER JOIN (
			SELECT
				u_mattress_mx_mtrl.mattressid,
				u_mattress_mx_mtrl.mtrlid
				,u_mattress_formula.formulakind as formulakind
			FROM u_mattress_mx_mtrl
			LEFT JOIN u_mattress_formula On u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
			WHERE formulatype = 99
		) vv_mattress on vv_mattress.mattressid = u_mattress.mattressid
		LEFT OUTER JOIN u_bednetmx on u_bednetmx.bednetid = vv_mattress.mtrlid
	</selectstr>
	<where>
		<when notnull="@arg_mattressid">
			u_mattress.parentid = @arg_mattressid OR  parentid = (
				SELECT parentid FROM u_mattress WHERE mattressid = @arg_mattressid and parentid > 0
			)
		</when>
	</where>
	<orderstr>
		mattressid
	</orderstr>
	<displayfields>
		<field field="mattress_width" datatype="integer">床垫宽/CM</field>
		<field field="mattress_length" datatype="integer">床垫长/CM</field>
		<field field="mattress_height" datatype="integer">床垫高/CM</field>
		<field field="spring_qty_width" datatype="number">
			弹簧排列
			个数-宽
		</field>
		<field field="spring_qty_length" datatype="number">
			弹簧排列
			个数-长
		</field>
		<field field="mattresscode">报价唯一码</field>
	</displayfields>
</select>
