MySQL Forums
Forum List  »  Italian

Problema con query
Posted by: Alfredo Camaiti
Date: January 15, 2009 11:52AM

Vorrei, se possibile, con un'unica query interrogare il DB, verificare se esiste un dato valore in un campo, ed in caso negativo eseguire una INSERT, altrimenti fare un UPDATE sommando un valore ad un campo della tabella.

Ho provato con:
IF
(
   SELECT id_user FROM tabella WHERE id_user=4 AND data = CURDATE()
)
IS NULL THEN
(
   INSERT INTO tabella (id_user,valore,data) VALUES (4,1,CURDATE())
)
ELSE
(
   UPDATE tabella SET valore=valore+1 WHERE id_user = 4 AND data = CURDATE()
)
END IF
Ma la query restituisce errore:
#1064 - You have an error in your SQL syntax;

La versione MySQL รจ: 5.0.32-Debian_7etch8-log

Qualche suggerimento su come risolvere il problema?

Grazie in anticipo
Excalibur



Edited 2 time(s). Last edit at 01/15/2009 11:55AM by Alfredo Camaiti.

Options: ReplyQuote


Subject
Views
Written By
Posted
Problema con query
5081
January 15, 2009 11:52AM
3345
January 16, 2009 03:37AM
3488
January 16, 2009 01:17PM
3440
January 16, 2009 05:15PM
3285
January 17, 2009 11:18AM


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.