日期:2014-05-18 浏览次数:20580 次
查询语句: SELECT *, dbo.F_GetSuccessTradeProportion(vmt.ClinchADealPublishNum, vmt.PublishNum) AS SuccessTradeProportion, dbo.F_GetSuccessTradeProportion(vmt.AppealedPublishNum, vmt.PublishNum) AS AppealTradeProportion from ##VendorMangerTable vmt F_GetSuccessTradeProportion函数: Create FUNCTION F_GetSuccessTradeProportion ( @SuccessOrAppealPublishNum INT, @PublishNum INT ) RETURNS FLOAT AS BEGIN DECLARE @proportion FLOAT IF @PublishNum<>0 AND @PublishNum IS NOT NULL AND @SuccessOrAppealPublishNum IS NOT NULL SET @proportion= CAST(@SuccessOrAppealPublishNum/@PublishNum*100 AS FLOAT) ELSE SET @proportion=0 RETURN @proportion END
F_GetSuccessTradeProportion函数: Create FUNCTION F_GetSuccessTradeProportion ( @SuccessOrAppealPublishNum INT, @PublishNum INT ) RETURNS FLOAT AS BEGIN DECLARE @proportion FLOAT IF @PublishNum<>0 AND @PublishNum IS NOT NULL AND @SuccessOrAppealPublishNum IS NOT NULL SET @proportion= CAST(@SuccessOrAppealPublishNum AS FLOAT)/@PublishNum*100 ELSE SET @proportion=0 RETURN @proportion END --try
------解决方案--------------------
--应是转换问题,按你的写法@SuccessOrAppealPublishNum小于@PublishNum时就会是0,这样试下 CAST(@SuccessOrAppealPublishNum/(@PublishNum*1.0)*100 AS FLOAT)