Solved

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

Posted on 2012-03-21
7
4,100 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:ilikeulike
Comment Utility
Yes, the select query worked fine.
0
 

Author Comment

by:ilikeulike
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now