Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009

    Question Unanswered: How to test values before insert (duplicity)

    My browser reported timeout error, so I posted this question one more again... please delete this duplicity thread.

    does anybody know how to test in script files if values already exists in a table(s), please?

    I have following data.sql script:
    INSERT INTO APPCONFIG (KEY, VALUE) VALUES ('someKey', 'someValue');
    ---(APPCONFIG is my custom table)

    I run this script using DB2 command line tool:
    DB2 -tf data.sql

    My problem is, that this script may be run more than once. So i need to add some IF statement to test if the key alerady exists. I've tried a lot of IF SELECT COUNT(*) FROM ... statements, but I still receive syntax errors etc.

    Can anybody help me, please?
    Last edited by frun; 04-20-09 at 10:15.

  2. #2
    Join Date
    Feb 2009
    If your KEY is really a unique key in table APPCONFIG - just do the insert and if the key value is duplicate of another already in the table, the return code will tell you that (-803)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts