且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在sql server 2008中的select语句中使用if else

更新时间:2023-01-19 17:51:19

尝试使用此代码。



Try with this code.

(select case when P.Factor1=' ' then 0
else P.Factor1
 end
from pr.PODTL P where FkItemCode=D.FkItemCode and DocCode=@ParentDocCode) as ***erageAmt


EG







E.G.



DECLARE @compareprice money, @cost money 
EXECUTE Production.uspGetList '%Bikes%', 700, 
    @compareprice OUT, 
    @cost OUTPUT
IF @cost <= @compareprice 
BEGIN
    PRINT 'These products can be purchased for less than


' + RTRIM(CAST( @ compareprice AS varchar 20 )))+ ' 。'
END
ELSE
PRINT ' 此类别中所有产品的价格超过
'+RTRIM(CAST(@compareprice AS varchar(20)))+'.' END ELSE PRINT 'The prices for all products in this category exceed