MySQL Forums
Forum List  »  Newbie

IF statement
Posted by: didaniman
Date: July 29, 2005 12:18AM

Lectori salutem (hail reader)

After about five hours trying, I still can't get this statement to work, I hope anyone can help me with this:

SET @i := 0;
SELECT @i := `id` FROM `files` WHERE `name` LIKE 'readme.txt%' AND `path` LIKE '/docs/%';
CASE
WHEN @i = NULL THEN INSERT INTO `files` (`name`, `path`, `server`, `dir`, `timestamp`, `size`) VALUES ('readme.txt', '/docs/%', '1', 'no', NOW(), 0)
WHEN @i > 0 UPDATE `files` SET `timestamp` = NOW() where `id` = @i
END CASE;

Or this, for that matter:

SET @i := 0;
SELECT @i := `id` FROM `files` WHERE `name` LIKE 'readme.txt%' AND `path` LIKE '/docs/%';
IF @i > 0 THEN UPDATE `files` SET `timestamp` = NOW() where `id` = @i
ELSE
INSERT INTO `files` (`name`, `path`, `server`, `dir`, `timestamp`, `size`) VALUES ('readme.txt', '/docs/%', '1', 'no', NOW(), 0)
END IF;

Or, if anyone get's the point of this statement, and has another method, please post as well.
Thanks in advance,

Daan Meijer

Options: ReplyQuote


Subject
Written By
Posted
IF statement
July 29, 2005 12:18AM
July 29, 2005 01:22AM
July 30, 2005 02:33PM
July 31, 2005 12:54PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.