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
Inner Join VS Multiple Table Names in "From"
Writing a Subquery Using Zend Db
SQL Combine Two Columns in Select Statement
How to Compare Software Versions Using SQL Server
Why No Output When Plsql Anonymous Block Completes
How to Create Daylight Savings Time Start and End Function in SQL Server
How to Generate Date Series to Occupy Absent Dates in Google Biqquery
SQL Error: Ora-02291: Integrity Constraint
Select Rows with Maximum Column Value Group by Another Column
SQL Not Displaying Null Values on a Not Equals Query
Update Int Column in Table with Unique Incrementing Values
Re-Order Columns of Table in Oracle
Case .. When Expression in Oracle SQL
How to Restore Postgresql Dump File into Postgres Databases
With (Nolock) VS Set Transaction Isolation Level Read Uncommitted