Home > Net >  Convert this excel formula so it can work on SQL?
Convert this excel formula so it can work on SQL?

Time:12-30

So it's been 1 week and I can't seem to figure it out.

=IF(D8="","",(IF((OR(R8<-3000,R8>3000)),"Outlier", IF((AND(S8>=-50%,S8<=50%,T8>=-50%,T8<=50%)),"Matched", IF((OR(AB8<-50%,AB8>50%)),"Outlier","Matched")))))

Thank you!!

I tried doing it on my own but I got mad and deleted everything so I can't put any of what I did here haha

CodePudding user response:

Assuming your column/field names are D, R, S, T and AB - from table #myTab

SELECT CASE 
  WHEN D = ',' AND (R < -3000 OR R > 3000) THEN 'Outlier'
  WHEN D = ',' AND (S >= -50 AND S <= 50 AND T >= -50 AND T <= 50) THEN 'Matched'
  WHEN D = ',' AND (AB < -50 OR AB > 50) THEN 'Outlier'
  WHEN D = ',' THEN 'Matched'
  ELSE NULL END
  AS Result
FROM #myTab;

Note this is written with the D = ',' so that each line stands alone - in case you want to modify it.

Otherwise, you can make the first check to be WHEN D <> ',' THEN NULL then remove the later checks on D.

  • Related