SQL if else子句可以在里面选择吗?

The*_*ewM 3 sql sql-server sql-server-2000

我怀疑这是可能的,但这里有.

我需要制定一个SQL查询(绝对不允许存储过程),它执行以下操作:

Select A.valueFromTable -B.ValueFromTable As result
From table as A inner join table as B
on A.ValueID = B.ValueID
Where ValueID =5
Run Code Online (Sandbox Code Playgroud)

但我需要条件:

if (result <0)
Begin
select A As result ....
end
else
select A-B as result ...
Run Code Online (Sandbox Code Playgroud)

任何帮助都会受到高度赞赏,即使它确认无法完成.

从搜索中我相信我目前使用的SQL Server版本是8.0

Fil*_*vić 5

Select 
    CASE
        WHEN A.valueFromTable -B.ValueFromTable < 0 THEN A.valueFromTable 
    ELSE A.valueFromTable -B.ValueFromTable END As result
From table as A inner join table as B
on A.ValueID = B.ValueID
Where ValueID =5
Run Code Online (Sandbox Code Playgroud)