CREATEFUNCTION[DBO].[FUN_RATE]
(@PARTIDINT,@ENIDINT,@SOURCEIDINT,
@QUALITYIDINT,@COUNTINT)
RETURNSFLOATAS
BEGIN
DECLARE@QXSFLOAT,@GFLOAT,@RATEFLOAT
IF(@ENID=NULL)OR(@PARTID=NULL)OR(@SOURCEID=NULL)OR(@QUALITYID=NULL)
BEGIN
RETURN(0.0)
END
SELECT@QXS=ISNULL(XS,0)FROMTABLEQUALITYWHEREID=@QUALITYID
SELECT@G=ISNULL(FRATE_G,0)FROMTABLEFAILURERATE
WHERE(SUBKINDID=@PARTID)AND(ENID=@ENID)AND(DATASOURCEID=@SOURCEID)
AND(((ISNULL(MINCOUNT,0)<=ISNULL(@COUNT,0))
AND(ISNULL(MAXCOUNT,0)>=ISNULL(@COUNT,0)))
OR(ISNULL(@COUNT,0)>ISNULL(MAXCOUNT,0)))
SET@RATE=ISNULL(@QXS*@G,0)
RETURN(@RATE)
END |