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 > Need help with set of substring

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-09-10, 16:52
Deb Locy Deb Locy is offline
Registered User
 
Join Date: Jul 2010
Posts: 5
Need help with set of substring

I am trying to execute the following but am getting a syntax error. DB2 version I am using is 8.1.

UPDATE SCE7000
SET SUBSTR(VNDRNOTE1RSLT001,19,9) = '777777777'
WHERE SUBSTR(VNDRNOTE1KEY,1,4) = 'SAGE'
AND SUBSTR(VNDRNOTE1KEY,5,10) = :WS-SEL-VNDR-NBR
AND SUBSTR(VNDRNOTE1RSLT001,19,9) = :WS-SEL-SS-ID

Any suggestions would be greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 07-09-10, 17:01
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I think you want something like :

Code:
UPDATE SCE7000
SET VNDRNOTE1RSLT001 =  SUBSTR(VNDRNOTE1RSLT001,1,18) || '777777777' ||SUBSTR(VNDRNOTE1RSLT001,28) 
WHERE SUBSTR(VNDRNOTE1KEY,1,4) = 'SAGE'
AND SUBSTR(VNDRNOTE1KEY,5,10) = :WS-SEL-VNDR-NBR
AND SUBSTR(VNDRNOTE1RSLT001,19,9) = :WS-SEL-SS-ID
Andy
Reply With Quote
  #3 (permalink)  
Old 07-09-10, 17:28
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
I agree with Andy.

Additional notes.
Note(1):
I doubt table design, because many SUBSTRs are used for columns.
It would be better to separate columns, like:
VNDRNOTE1KEY
---> VNDRNOTE1KEY_1 CHAR(4) NOT NULL , VNDRNOTE1KEY_VNDR_NBR CHAR(10) NOT NULL , .....
VNDRNOTE1RSLT001
---> VNDRNOTE1RSLT001_1 CHAR(18) , VNDRNOTE1RSLT001_SS_ID CHAR(9) , .....

Note(2):
There may be a possibility to get better performance by modifying conditions...
Code:
/*
 WHERE SUBSTR(VNDRNOTE1KEY , 1 ,  4)     = 'SAGE' 
   AND SUBSTR(VNDRNOTE1KEY , 5 , 10)     = :WS-SEL-VNDR-NBR 
*/
 WHERE VNDRNOTE1KEY LIKE 'SAGE' || :WS-SEL-VNDR-NBR || '%'
Reply With Quote
  #4 (permalink)  
Old 07-12-10, 07:31
Deb Locy Deb Locy is offline
Registered User
 
Join Date: Jul 2010
Posts: 5
Thumbs up This looks good.

The table design is delivered vendor code so it cannot be modified. However, the changes for the SQL look good and I will be testing them today. Thanks so much for the prompt responses. I am very optimistic about your suggestions.
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