create function getTax(LEAS_FORM varchar(2), taxType varchar(12), indate varchar(32)) returns double(3,2)
BEGIN
RETURN (
	select
		CASE WHEN taxType='租息' then (ROUND(TI.INTEREST_RATE/100,2)+1)
		WHEN taxType='本金' THEN (ROUND(TI.CORPUS_RATE/100,2)+1)
		WHEN taxType='手续费' THEN (ROUND(TI.HAND_RATE/100,2)+1)
		WHEN taxType='留购价' THEN (ROUND(TI.NOMINAL_RATE/100,2)+1)
		WHEN taxType='GPS' THEN (ROUND(TI.gps_install_fee/100,2)+1)
		WHEN taxType='违约金' THEN (ROUND(TI.penalty/100,2)+1)
		WHEN taxType='租金' THEN (ROUND(TI.rent/100,2)+1)
		WHEN taxType='逾期利息' THEN (ROUND(TI.break_money/100,2)+1)
		end
		as tax
	from
		TAX_INFO TI
	WHERE 
		TI.LEASE_FORM = LEAS_FORM
	AND	DATEDIFF(left(indate,10),TI.CONTRACT_DATE) =(SELECT MIN(DATEDIFF(LEFT(indate,10),CONTRACT_DATE)) AS CONTRACT_DATE FROM TAX_INFO WHERE lease_form=LEAS_FORM	
	AND 	DATEDIFF(LEFT(indate,10),CONTRACT_DATE)>=0
	));
END;

