Home » excel » sql server – Converting Excel Formula involving *OR to TSQL

sql server – Converting Excel Formula involving *OR to TSQL

Posted by: admin May 14, 2020 Leave a comment


I’m trying to convert this formula into T-SQL.


Does anyone know what the *OR actually means?

The columns C, D, F are all Date fields.

For example

enter image description here

For the first line, this part of the formula IF(D6>F6,D6-C6-1,F6-C6-1) returns 35 and the second part of the formula IF(F6-C6-1<0,0,F6-C6-1) returns 35 as well. So shouldn’t the result be 35 x 35 = 1225. The correct answer is 35 however.

How to&Answers:

As per my earlier comment:

The second parameter in the OR would be optional. As a matter of fact, or will just return ‘TRUE’ if any of it’s paramaters is ‘TRUE’, no matter the amount of (optional) parameters you use. The ‘OR’ in this case just evaluates the outcome of the second ‘IF’ (which is 35). So > ‘OR(35)’ which evaluates to TRUE. Since you multiply this will again evaluate to ’35*1′ being your final result. The formula is looking strange because ‘OR’ would always return true in this case. The formula might as well just be ‘=IF(D6>F6,D6-C6-1,F6-C6-1)’

<a href="https://exceptionshub.com/category/sql-server”>More Answers>