TlalocW
TlalocW

Reputation: 1

MySQL Stored Procedures - Sending Variables that Might or Might Not Be Empty

I'm sending in a variable _activeflag which can be 1 or 0 (char, not smallint). If I send in a blank for _activeflag, I want to get all records, but if I send in a 1 or 0, I want records with those activeflags so my where clause is

WHERE ( activeflag = _activeflag OR _activeflag = "" )

Is that not correct? What exactly does that line mean? I had convinced myself from some other page that I can't find that it's like a shorthand if statement. If _activeflag is not blank then search on the column specified. Am I wrong?

Upvotes: 0

Views: 19

Answers (1)

Rahul
Rahul

Reputation: 77896

I think you should probably check for IS NULL rather like

WHERE ( activeflag = _activeflag OR _activeflag IS NULL )

Upvotes: 1

Related Questions