SQL Server 2008 Iif Statement Does Not Seem Enabled

SQL Server 2008 IIF statement does not seem enabled

As noted, IIF is a SQL2012 feature.

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

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

IIF(...) not a recognized built-in function

IIF comes from SQL 2012. Before then, you can use CASE:

SET @SomeVar = @SomeOtherVar + CASE
WHEN @SomeBool
THEN 'value when true'
ELSE 'value when false'
END

IIF 'Incorrect syntax near' error at SQL Server 2014

This happens when you're not running on a correct version of SQL Server, or if the compatibility level of the database isn't set sufficiently.

To check compatibility level:

select compatibility_level 
from sys.databases
where name = '<database name>'

To alter compatibility level:

alter database <database-name> 
set compatibility level = 110 -- SQL Server 2012

List of compatibility levels: https://msdn.microsoft.com/en-us/library/bb510680.aspx

Visual Basic - Nested IF in IIF with OrElse

This should work (once you integrate it into the rest of the expression)

Iif(Fields!DonationAmount.Value < 10, 10, Fields!DonationAmount.Value)

How to convert Access SQL code with IIf() functions to T-SQL?

Your instinct is correct that CASE ... WHEN would be useful. But don't think in terms of one massive CASE ... WHEN expression as a substitute for all those Access IIf expressions. Instead use a separate CASE ... WHEN for each IIf ... and sum up their values as you did with the IIf expressions.

Here is a brief example based on only 2 of those fields to get you started:

select
case when s.DataEntry1=0 then 1 else 0 end
+ case when s.DataEntry2=0 then 1 else 0 end AS CoachingCount
FROM table1 AS s

SQL Server: Use different date format in Select when selected date equals current date

you will not match to getdate() using equals, and you need to set getdate()'s time to midnight

select
case when G.modTime >= dateadd(day, datediff(day,0, getdate() ), 0)
then ('Today at ' + CONVERT(VARCHAR(5), G.modTime, 108))
else
CONVERT(VARCHAR(11), G.modTime, 106)
end AS modTime
from G

Above I have used: dateadd(day, datediff(day,0, getdate() )

Instead you could use: cast(getdate() as date)

both, have the effect of giving you "today" at 00:00:00

Trying to access the Visibility property to tell if sub report is visible

An IIF() statement requires 3 parameters. There are 3 in the first so it works the others only have 2 so will not.

Your IIF() statements should take look similar to

=IIF([Condition to Check],[Do when condition true],[Do when condition false])

http://msdn.microsoft.com/en-us/library/ms157328.aspx#DecisionFunctions



Related Topics



Leave a reply



Submit