Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional NOT NULL case SQL

I am trying to calculate a field and I want it to behave differently depending on if one of the columns happens to be null. I am using MySQL

CASE 
  WHEN reply.replies <> NULL THEN
  24/((UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(qcr.LAST_MOD_TIME)+3600)/3600)*(ces.EXPERT_SCORE+2.5*scs.SIMILARITY)*(EXP(-reply.replies))
  ELSE 1
END as ANSWER_SCORE

Is this the right syntax?

like image 902
Spencer Avatar asked Jan 27 '11 19:01

Spencer


1 Answers

You need to have when reply.replies IS NOT NULL

NULL is a special case in SQL and cannot be compared with = or <> operators. IS NULL and IS NOT NULL are used instead.

like image 150
Joe Stefanelli Avatar answered Sep 28 '22 03:09

Joe Stefanelli