嗨我在我的sql程序中有这样的过滤器:
IF (@LastLoginStartDate IS NOT NULL)
BEGIN
SET @sqlFilters = @sqlFilters + 'AND IIF(DPL.[LastLoginDate]=''0001-01-01 00:00:00.0000000'',''1901-01-01 00:00:00.0000000'',DPL.[LastLoginDate]) >= @LastLoginStartDateUTC ';
END
但这会给我一个错误。那么如何将值1901-01-01设置为0001-01-01之类的值并与参数@LastLoginStartDateUTC进行比较?
我收到错误:
Msg 102, Level 15, State 1, Line 115
Incorrect syntax near 'IIF'.
答案 0 :(得分:2)
Iif在Access中使用但不是有效的SQL Server。相反,您应该使用CASE语法,如下所示:
AND CASE WHEN DPL.[LastLoginDate]='0001-01-01 00:00:00.0000000'
THEN '1901-01-01 00:00:00.0000000 '
ELSE DPL.[LastLoginDate]
END >= @LastLoginStartDateUTC