<?xml version="1.0" encoding="utf-8" ?>
<select>
	<selectstr>
		select u_mtrl_price.mtrlid,
			u_mtrl_price.name as mtrlname,
			ISNULL(u_mtrl_price_pricelist.price, 0) AS pricelistprice,
			u_mtrltype.dannum1_rate,
			u_mtrltype.dannum2_rate,
			u_mtrltype.dannum3_rate,
			u_mtrltype.dannum4_rate
		from u_mtrl_price
		LEFT JOIN u_mtrl_price_pricelist ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
		LEFT OUTER JOIN u_mtrltype ON u_mtrl_price.mtrltype = u_mtrltype.mtrltypeid
	</selectstr>
	<where>
		<when>
			u_mtrl_price.mtrltype = 2
		</when>
		<when notnull="@arg_pricelistid">
			u_mtrl_price_pricelist.pricelistid = @arg_pricelistid
		</when>
		<when notnull="@arg_bednetid" arg_bednetid!="0">
			u_mtrl_price_pricelist.pricelistid = (select pricelistid from u_dept where deptid = (select deptid from u_bednet where bednetid = @arg_bednetid))
		</when>
		<when notnull="@arg_deptid">
			u_mtrl_price_pricelist.pricelistid = (select pricelistid from u_dept where deptid = @arg_deptid)
		</when>
	</where>
	<displayfields>
	</displayfields>
</select>
