DROP FUNCTION IF EXISTS fn_GetWarrantyItemName;
CREATE FUNCTION fn_GetWarrantyItemName("AmbserID" UUID)
RETURNS varchar(255) AS
 $$
Begin
	return
	(
		select LEFT(t5.Name, CHARINDEX('|', t5.Name) - 1)
 		from AKUZ.T_AMBSER t1
   		inner join
  			AKUZ.T_AMBREE t2 
			on t1.AmbRee = t2.AmbReeID 
   		inner join 
   			AKUZ.T_AMBMAIN t3 
			on t2.AmbMain = t3.AmbMainID
   		inner join
   			AKUZ.T_WARRANTY_PROGRAM_GROUP t4 
   			on t3.WarrantyProgram = t4.WarrantyProgram
   		inner join
   			AKUZ.T_WARRANTY_PROGRAM_ITEM t5 
   			on t4.WarrantyProgramGroupID = t5.WarrantyProgramGroup 
   			and t5.Code = t1.Code
   		where t1.AmbserID = "AmbserID"
   		limit 1
	);
END $$
language plpgsql volatile;