CREATE FUNCTION [DBO].[FUN_RATE] (@PARTID INT,@ENID INT,@SOURCEID INT, @QUALITYID INT,@COUNT INT) RETURNS FLOAT AS BEGIN DECLARE @QXS FLOAT, @G FLOAT, @RATE FLOAT IF (@ENID=NULL) OR (@PARTID=NULL) OR (@SOURCEID=NULL) OR (@QUALITYID=NULL) BEGIN RETURN(0.0) END SELECT @QXS= ISNULL(XS,0) FROM TABLEQUALITY WHERE ID=@QUALITYID SELECT @G=ISNULL(FRATE_G,0) FROM TABLEFAILURERATE 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
|