本文介绍了SQL Server 2008 IIF 语句似乎未启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在选择语句中使用 IIF().布尔表达式检查字段值是否等于空字符串.语法如下:

I am trying to use IIF() in a select statement. The boolean expression checks to see if a fields value is equal to an empty string. The syntax is like so:

SELECT IIF(field = '','ONe action','Another')

我收到错误接近 =" 的语法错误

I am getting the error "syntax error near ="

我尝试了一个简单的测试:

I tried a simple test:

SELECT IIF(2 > 1, 'yes','no')

并且我得到 "syntax errror near >"

这让我相信 IIF 根本不起作用.

This is leading me to believe that IIF is not working at all.

我正在使用 SQL SERVER 2008 R2,是否需要配置一些东西以允许 IIF() 工作?有什么关于我遗漏的语法吗?我的测试很简单,但仍然出现语法错误.

I am using SQL SERVER 2008 R2, is there something that needs to be configured to allow IIF() to work? Is there something about the syntax that I am missing? My test is simple as can be and I still get the syntax error.

任何帮助将不胜感激.非常感谢!

Any help would be appreciated. Thanks much!

推荐答案

如前所述,IIF 是 SQL2012 的一个特性.

As noted, IIF is a SQL2012 feature.

将您的 IIF 替换为 CASE(无论如何 SQL 2012 都会这样做)

Replace your IIF with a CASE ( Which is what SQL 2012 would do anyway )

 SELECT CASE field WHEN '' THEN 'ONe action' ELSE 'Another' END

这篇关于SQL Server 2008 IIF 语句似乎未启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 15:27