Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

AS400 SQL  - Updating records from one file with data from another file

Posted on 2012-03-21
7
4,476 Views
Last Modified: 2012-03-22
Hi there, can anybody help me with an SQL problem i am having on our iseries?

I am trying to update the std cost of a range of parts.

The file is TSTT2F1/INP60, and the Stockroom is STRC60, the Company is NC and the Standard Cost is SCSU60.

I have created a file with the new prices (JAMES/NEWSTDCOST), and uploaded it to the AS400 (see sample data below)
CONO60      STRC60      ABCPART      STDCOST
NC      IN      3680      24.26
NC      IN      3870      27.13
NC      IN      3871      22.57

but I am not sure how to word the SQL statement to pick up all the different prices for each part. The parts may or may not exist in INP60 so i need to pick up the data for those that do.

The statement I have tried unsuccessfully is :
UPDATE TSTT2F1/INP60 SET SCSU60 = 'STDCOST' WHERE CONO60='NC' AND STRC60='IN' AND EXISTS (SELECT ABCPART FROM JAMES/NEWSTDCOST WHERE ABCPART=PNUM60 AND SCSU='STDCOST')

VALUE FOR COLUMN OR VARIABLE SCSU60 NOT COMPATIBLE.                

Hopefully you can help me with this?

Thanks

JAmes
0
Comment
Question by:ilikeulike
  • 4
  • 2
7 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 400 total points
ID: 37746728
try

UPDATE TSTT2F1/INP60   t1
SET SCSU60 = (select STDCOST from FROM JAMES/NEWSTDCOST
                     WHERE ABCPART=t1.PNUM60)
WHERE CONO60='NC'
AND STRC60='IN'
AND EXISTS (SELECT ABCPART
                     FROM JAMES/NEWSTDCOST
                     WHERE ABCPART=t1.PNUM60)
0
 

Author Comment

by:ilikeulike
ID: 37748077
Hi Momi_sabag
Thanks for your reply. I have tried that but get the error:
Token / was not valid. Valid tokens: ) UNION, with the cursor highligting the / on the "FROM JAMES/NEWSTDCOST"

Just a question, but what does the t1 mean?

Sorry to sound stupid?

Thanks

James
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 37748143
t1 is just an alias for the table so that you could use it in the subquery
i'm not as as400 guy, so don't know what to tell you about the / problem

does this query works?
SELECT ABCPART
                     FROM JAMES/NEWSTDCOST
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:ilikeulike
ID: 37748258
Yes, the select query worked fine.
0
 

Author Comment

by:ilikeulike
ID: 37748327
I have retried as i had a problem in my code. I now get :
UPDATE tstt2f1/inp60 t1     SET SCSU60 = (SELECT STDCOST FROM james/
newstdcost  WHERE ABCPART = t1.PNUM60)                              
                                                                     
WHERE CONO60='NC' and STRC60='IN'                                    
                                                                     
AND EXISTS (SELECT ABCPART FROM james/newstdcost                    
WHERE ABCPART = t1.PNUM60)
 
Result of SELECT more than one row.  

Any thoughts?

Thanks

James
0
 
LVL 27

Assisted Solution

by:tliotta
tliotta earned 100 total points
ID: 37749050
SET SCSU60 = (SELECT STDCOST FROM james/newstdcost  WHERE ABCPART = t1.PNUM60)

If more than one row is being selected, it means that ABCPART is found more than once in james/newstdcost. In order to narrow it down, you'll need to make the WHERE clause more selective. You probably need to include both CONO60 and STRC60 so that you get the cost for that part only from that Company and that Stock Room.

And if that doesn't do it, you need to verify that there is in fact only one row for each Company/Stock Room/Part combination.

Tom
0
 

Author Closing Comment

by:ilikeulike
ID: 37751962
Hi Guys,  thanks for all your help. The solution worked a treat (thanks momi_sabag) once i had removed a duplicate entry from my data (thanks Tom)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to apply the SSL on iseries and WAS application 1 127
DB2 return first match 3 116
vmware on IBM X3960 with HA - Idiots Guide 8 121
Monitoring IBM System x through PRTG 7 140
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question