0

I'd like to combine an insert query with a "where not exists"

Here my SQL :

INSERT INTO MYTABLE (ACT_ORDER, MNU_ACTION, ACT_STATUT, ACT_BEFORE, ACT_AFTER)
SELECT (1,'acOuvPOS', 'T', 'T', NULL)
WHERE NOT EXISTS (SELECT * FROM MYTABLE WHERE  (MNU_ACTION ='acOuvPOS' AND ACT_STATUT = 'T' AND ACT_BEFORE= 'T');

But when I execute the SQL I have this problem

Invalid token. Dynamic SQL Error. SQL error code = -104. Token unknown - line 2, char 8. ,.

How can I resolve this please Thanks in advance

Alex K.
  • 171,639
  • 30
  • 264
  • 288
mimou_2009
  • 47
  • 7

2 Answers2

0

INSERT INTO MYTABLE (ACT_ORDER, MNU_ACTION, ACT_STATUT, ACT_BEFORE, ACT_AFTER) SELECT 1,'acOuvPOS', 'T', 'T', NULL WHERE NOT EXISTS (SELECT * FROM MYTABLE WHERE MNU_ACTION ='acOuvPOS' AND ACT_STATUT = 'T' AND ACT_BEFORE= 'T')

Mansoor
  • 4,061
  • 1
  • 17
  • 27
0

you can simply say :

IF ( NOT EXISTS (SELECT * FROM MYTABLE WHERE (MNU_ACTION ='acOuvPOS' AND ACT_STATUT = 'T' AND ACT_BEFORE= 'T') BEGIN INSERT INTO MYTABLE (ACT_ORDER, MNU_ACTION, ACT_STATUT, ACT_BEFORE, ACT_AFTER) (1,'acOuvPOS', 'T', 'T', NULL) END

Pouya Kamyar
  • 133
  • 1
  • 9