SQL Server 2005 中的 IIF 语句 [英] IIF statement in SQL Server 2005
问题描述
IIF
语句是否存在于所有版本的 SQL Server 中?
Does IIF
statement exists in all version of SQL Server ?
我查看了 MSDN 上的教程.
I have checked a tutorial on MSDN.
但是当我试图在我的机器上运行这段代码时
But when I tried to run this code on my machine
DECLARE @newDate datetime
SET @newDate = CONVERT(varchar, {fn NOW()}, 111)
SELECT IIF(@newDate > '2010/12/2', 'Greater', 'smaller')
但我收到'>'附近的语法不正确"的错误消息.
But I am getting error of "Incorrect syntax near '>'."
有人可以为我提供一个 SQL Server 2005 中存在 IIF
语句的示例吗?
Can someone provide me an example in SQL Server 2005 for the existence of the IIF
statement?
推荐答案
那个IIF
语句只存在于MDX——SQL Server的查询语言分析 服务 - SQL Server 的数据仓库端.
That IIF
statement only exists in MDX - the query language for SQL Server Analysis Services - the datawarehousing side of SQL Server.
Plain T-SQL 没有IIF
语句.
Plain T-SQL does not have an IIF
statement.
在 T-SQL 中你能做的最好的事情是使用 CASE.... WHEN... THEN...
语句.
The best you can do in T-SQL is use the CASE.... WHEN... THEN...
statement.
这篇关于SQL Server 2005 中的 IIF 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!