I understand that this question (which shows up at the top of google results for “sql server inline if”) is 2 years old, but with SQL Server 2012, the answers are somewhat outdated. It also appears to be a duplicate of SQL inline if statement type question, but that question (being an even older one), doesn’t have an up to date answer either.
In SQL Server 2012 you can use the IIF
function:
IIF ( boolean_expression, true_value, false_value )
Example:
SELECT IIF(someColumn = 1, 'yes', 'no')
Related Contents:
- SQL Server Profiler – How to filter trace to only display events from one database?
- How can you represent inheritance in a database?
- SQL Server Text type vs. varchar data type [closed]
- How do I flush the PRINT buffer in TSQL?
- insert a NOT NULL column to an existing table
- SQL Server Installation – What is the Installation Media Folder?
- “Server” vs “Data Source” in connection string
- No process is on the other end of the pipe (SQL Server 2012)
- SQL Server 2008 Windows Auth Login Error: The login is from an untrusted domain
- SQL-Server: Is there a SQL script that I can use to determine the progress of a SQL Server backup or restore process?
- What’s the best way to store co-ordinates (longitude/latitude, from Google Maps) in SQL Server?
- How can you tell what Tables are taking up the most space in a SQL Server 2005 Database?
- How to query for Xml values and attributes from table in SQL Server?
- The database owner SID recorded in the master database differs from the database owner SID
- How to Use UTF-8 Collation in SQL Server database?
- SQL count rows in a table
- SQL Server Profiler : How to specify multiple values for “NOT LIKE” column filter
- SQL – The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
- Is it safe to have SQL Server auto-shrink turned on?
- How to update a CLR Assembly without dropping assembly from SQL Server
- SQL Server: combining multiple rows into one row
- UPDATE OUTPUT into a variable
- Is a single SQL Server statement atomic and consistent?
- Error: TCP Provider: Error code 0x2746. During the Sql setup in linux through terminal
- Diagnosing Deadlocks in SQL Server 2005
- Restoring SQL Server backup to Azure SQL Database
- What is the use of WITH TIES keyword in SELECT statement in SQL Queries?
- How to import a bak file into SQL Server Express
- How to set value to variable using ‘execute’ in t-sql?
- Cannot find either column “dbo” or the user-defined function or aggregate “dbo.Splitfn”, or the name is ambiguous
- 64 bit Microsoft SQL Server Data Tools
- Replace single quotes in SQL Server
- Scheduled run of stored procedure on SQL server
- Does inserting data into SQL Server lock the whole table?
- How To change the column order of An Existing Table in SQL Server 2008
- SQL Server: UPDATE a table by using ORDER BY
- Cannot use special principal dbo: Error 15405
- Select All as default value for Multivalue parameter
- Find a string by searching all stored procs in SQL Server Management Studio 2008
- SQL Server truncation and 8192 limitation
- Get last 30 day records from today date in SQL Server
- SSIS Excel Connection Manager failed to Connect to the Source
- How do I add a “last modified” and “created” column in a SQL Server table?
- Update SQL with consecutive numbering
- Differences Between Drivers for ODBC Drivers
- In SSMS, how do I change a SQL query window’s tab name?
- SQL Server, How to set auto increment after creating a table without data loss?
- How to connect to SQL Server with windows authentication from Node.JS using mssql module
- How to save select query results within temporary table?
- Delete from a table based on date [closed]