[英]What's wrong this T-SQL statement?
Why is this throwing an error on the equal sign? 为什么这会在等号上抛出错误?
select IIF((SUBSTRING('A1234', 1, 1) = 'A'), TRUE, FALSE) as IsAustraliaUser
Error: 错误:
Msg 102, Level 15, State 1, Line 1 Msg 102,Level 15,State 1,Line 1
Incorrect syntax near '='. '='附近的语法不正确。
你应该用CASE替换IIF,在SQL Server中也不存在TRUE和FALSE,你可以使用VARCHAR或BIT
select CASE WHEN SUBSTRING('A1234', 1, 1) = 'A' THEN 'TRUE' ELSE 'FALSE' END as IsAustraliaUser
I don't think SQL supports this syntax of IIF (unless you're using 2012), replace with case. 我不认为SQL支持IIF的这种语法(除非你使用2012),用case替换。
SELECT CASE WHEN ( SUBSTRING('A1234', 1, 1) = 'A' ) THEN 'TRUE'
ELSE 'FALSE'
END AS IsAustraliaUser
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.