Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Refactor T-SQL Code to Databricks SQL Undefined function: 'IIF'

When executing the following T-SQL code with Databricks SQL I get the error:

Undefined function: ‘IIF’.

,ISNULL(RH.Exchange, ISNULL(IIF(SIB.Rate = 0, 1, CASE .....

This is because Databricks doesn’t recognize IIF. Can someone let me know the equivalent with Databricks SQL?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In databricks SQL , you can use iff function to acheive the same requirement of T-SQL’s iif function.

Syntax for iif function:

iff(cond, expr1, expr2)

here,

cond: a Boolean expression,
expr1: any expression which needs to be executed when the cond is true,
expr2: any expression which needs to be executed when the cond is false.

Reference: https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/functions/iff

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading