Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IF statement is not valid in this position

Tags:

sql

mysql

I have checked/compared SQL statement several times, but it is still not working. I am using WorkBench 6.3 with MySQL. It gives me an error:

1064 syntax error: 'IF' is not a valid input at this position.

IF(EXISTS(SELECT * FROM RECORDS WHERE FORMID = 200002016 AND TimeUploaded > '2016-07-17 03:13:39' AND TimeUploaded < '2016-07-17 03:13:39'))
Begin
    SELECT TimeUploaded from RECORDS
End;
like image 487
SCS Avatar asked Jul 17 '16 06:07

SCS


1 Answers

You cannot use IF in an SQL statement. You can only use it in a stored procedure or a function.

You can rewrite your statement like this:

SELECT TimeUploaded from RECORDS
WHERE FORMID = 200002016
  AND TimeUploaded > '2016-07-17 03:13:39'
  AND TimeUploaded < '2016-07-17 03:13:39'
like image 195
Racil Hilan Avatar answered Sep 21 '22 03:09

Racil Hilan