# Excel formulas to SQL • ### Question

• i couldnt solve this codes. If some one could help that would be great.

"E1335" =IF(D135=0,0,IF(AND(AU135/D135>=0.8,AU135/D135<1),1,ROUNDDOWN(AU135/D135,0)))

I did this:

CASE WHEN [D135] = 0 THEN 0

WHEN [AU135] / [D135] >= 0.8 AND [AU135] / [D135] < 1 THEN 1

ELSE Floor ([AU135] / [D135])

END AS E135,

here Comes the Problem in SQL since in this part it links back to (E135) the 1. if calculation and just fail.

"F135" =IF(C135=0,0,IF(E135=1,0,ROUNDDOWN((AU135-E135*D135)/C135,0)))

CASE WHEN [C135] = 0 OR E135 1 THEN 0

ELSE Floor ([AU135] - [E135] * [D135] / [C135]) END AS [F135]

"G135" =IF(B135=0,0,IF(E135=1,0,ROUNDDOWN((AU135-E135*D135-F135*C135)/B135,0)))

Wednesday, May 15, 2019 7:52 AM

### All replies

• It looks like you're missing an equality operator in this line:

CASE WHEN [C135] = 0 OR E135 1 THEN 0

It should be:

CASE WHEN [C135] = 0 OR E135 = 1 THEN 0

Eitan Blumin; SQL Server Consultant - Madeira Data Solutions

Wednesday, May 22, 2019 11:37 AM