If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to test values before insert

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-20-09, 10:03
frun frun is offline
Registered User
 
Join Date: Apr 2009
Posts: 21
Question 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.


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

I have following data.sql script:
---
CONNECT TO MyDB;
INSERT INTO APPCONFIG (KEY, VALUE) VALUES ('someKey', 'someValue');
CONNECT RESET;
---(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.
Reply With Quote
  #2 (permalink)  
Old 04-21-09, 09:48
db2dummy1 db2dummy1 is offline
Registered User
 
Join Date: Feb 2009
Posts: 114
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)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On