如何在SQL中用if else

如何在存储过程中进行用IF ELSE 运算我要进行两个数相除,有可能除数为0所以要用if else 来判断有会的高手速来帮忙,感谢感谢
set @TotalReceiveFiles = @TotalReceiveFiles + @ReceiveFilesTion;
set @TotalBackVolumes = @TotalBackVolumes + @BackVolumesTion;
set @TotalBackRate = @TotalBackRate + ((@BackVolumesTion / @ReceiveFilesTion) * 100);

第1个回答  2013-09-23
if else是嵌套语句。意思是如果什么什么否则就什么什么。不懂你的意思。 用法: if (@MyValue>0) begin 这里是大于0执行语句 end else begin 这里是小于或等于0执行语句 end本回答被网友采纳
第2个回答  2015-10-15
一般存储过程中 为嵌套语句 判断一个值 从而进行不同的操作 declare @a nvarchar(50)
select @a=a from 表名1
if @a='1'
begin
select * from 表名2 where c=@a

end
else
begin
select * from 表名2
end 纯手打 希望能帮到你 ,欢迎追问!
第3个回答  2013-09-23
if(@BackVolumesTion=0)begin 除数不能为0 这个时候你可以做一些提示什么的 或者有默认值endelsebegin set @TotalBackRate = @TotalBackRate + ((@BackVolumesTion / @ReceiveFilesTion) * 100);end