Skip to content
Advertisement

Mysql IF statement Error on Nested if sentence

I am trying to create a procedure to update the stopTime field on my works table. The query I am using is:

Shortly, the query should get the related results_ table stampTime as stopTime of works table’s related entry. If there is no table or empty table, the stampTime at the works table is used.

My problem occurs when there is no results_ table I’m looking for. The statement should check if related results_* table exists and if not, it should get the stampTime from works table.

But it also executes the statement below (i.e: ELSE part)

and I got the error (as expected)

I checked the parenthesis and commas multiple times. I think there is no mistake about it. What am I missing? It shouldn’t execute the ELSE part, but it does. Why?

Thanks.

OS: Raspbian

Mysql version: Mysql Ver 15.1 Distrib 10.3.22-MariaDB, for debian-linux-gnueabihf (armv8l) using readline 5.2

Advertisement

Answer

Like GMB alsready said you need some dynamic sql

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement