4
I am trying to insert a record into the table, but this record will only be inserted if it no longer exists there, so I am trying to do so:
INSERT INTO R01 (NUMERO,EXPORTADOR, IMPORTADOR, DATAANTECIPADO, STATUS)
VALUES
(64, 'CCB TESTE LTDA.', 'CCB TESTE LTDA.', (select cast('Now' as date) from rdb$database), 'A')
WHERE NOT EXISTS ( SELECT * FROM R01 WHERE NUMERO=64 ,SERIE='CTE' );
The error message is this:
Dynamic SQL Error. SQL error code = -104. Token Unknown - line 4, char 1. WHERE.
If there is a more elegant way to catch the date in Firebird I would also appreciate
– SneepS NinjA
This syntax does not exist. Firebird has a nice balcony of "UPDATE OR INSERT". See: http://www.firebirdsql.org/refdocs/langrefupd25-update-or-insert.html. If you have no update and if the record already exists you will simply do nothing, then a IF should solve your problem: http://www.janus-software.com/fbmanual/manual.php?book=psql&topic=98. If you can solve the problem with these commands post a complete answer to help the next one who passes by here better ;-)
– Caffé
@Anus with that one update or Insert it almost solved, the problem is that it updates every time the record is already there, going back to the initial state, my STATUS field will one hour change, and if you run sql again it will go back to the initial STATUS
– SneepS NinjA
1: More elegant way to pick up the date: CURRENT_DATE variable
– Edison de Brito