日期:2014-05-19  浏览次数:20646 次

请教SQL中的一个函数
请问:在SQL中,如果需要对某两个值进行判断分析,应该用什么函数?此函数的性质就诸如Excel中的IF函数,例如:
A=100,B=300
使用IF函数就是:if(A <> B, "错误 ", "正常 "),那么此语句使用SQL应该怎样书写?应该使用什么函数呢?

------解决方案--------------------
case when A <> B then '错误 '
else '正常 '
end
------解决方案--------------------
select case A when B then '正常 ' else '错误 ' end from [Table]
------解决方案--------------------
CREATE FUNCTION dbo.F_Test( @A int, @B int)
RETURNS varchar(100) AS
BEGIN

return (Select case when @A <> @B then '错误 ' else '正常 ' end)

END

Select dbo.F_Test(100,300)

------
错误
------解决方案--------------------
select case then A <> B then 'false ' else 'true ' end
------解决方案--------------------
Select case when A <> B then "错误 " else "正常 " end