Home » excel » Convert Excel 'if' function to SQL query

Convert Excel 'if' function to SQL query

Posted by: admin May 14, 2020 Leave a comment


I have a function like this:


This follows the syntax if(condition,true,false). I was looking for a way to convert this into an SQL query like so:

select case 
  when a>b then 
          when b>c then a 
          else b 
  else c 

I thought of splitting the input and passing it on my own, but I was hoping there was a better way to do this.
Any help is appreciated!
Thanks in advance.

How to&Answers:

You can use IIF function as well… Please check the link for description.

So for you it would be something like SELECT IIF (a > b, IIF ( B > C, A, B ), C ) AS Result;

Sytax is not tested but would work.