CREATE TEMPORARY TABLE temporal(
IP varchar(15) NULL
);
CREATE TEMPORARY TABLE temporal_2(
IP varchar(15) NULL
);
SELECT IF (NULL = (SELECT IP FROM temporal WHERE IP = '0' LIMIT 1),
(INSERT INTO temporal_2(IP) VALUES ('1')),(SELECT NULL LIMIT 1));
DROP TEMPORARY TABLE temporal;
DROP TEMPORARY TABLE temporal_2;
Error
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO temporal_2(IP) VALUES ('1')),(SELECT NULL LIMIT 1))' at line 2
I want to do this from SQL server but in MySQL. The equivalent of this:
CREATE TABLE #Temp (IP varchar(15))
INSERT #Temp (IP)VALUES (0)
IF NOT EXISTS (SELECT IP FROM #Temp WHERE IP = 0)
BEGIN
PRINT 'Entro'
END
DROP TABLE #Temp
See if what you want is to know why your IF doesn't work, it's simply because you have to use it inside a stored procedure to do an insert:
In this way you command to call the procedure:
Since there is no data in the 'temporary' table, it will insert into the 'temporary_2 table'
now if you insert into the 'temporary' table it will return this:
finally if you want to use conditionals it is better to use CASE, however you can only do certain operations but you can use it outside of a procedure: