Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...One of the best run forums I have used in years! ...I like the way the site is organized and your no tolerance of flames..."

Geography

Where in the world do Tek-Tips members come from?
dave3944 (Programmer)
8 May 12 13:44
Long time looker, first time poster. This is way over my head. I have spent 3 days looking and trying to solve this problem. Your help is greatly appreciated.
I am trying to populate an AS400 database with 11 fields. I am receiving a "duplicate entries" error. I would expect this, but I need a way to work around it. For instance, a single part number may have up to 5 or 6 different price codes depending on which customer is making the purchase. So, it is necessary to have the part number listed multiple times, but with different pricing codes. Here's what I have been trying so far (remember I'm a SQL newbie). INSERT INTO WEBPRDDT1.WBMSCUR (SPPTNO, SPDESC, SPLDTM, SPCATG, SPPRC1, SPPRC2, SPPRC3, SPPMBQ, SPDATE, SPATA, SPUSER) VALUES ('3408320018','PLASTIC SCREW','035','','0.25','0.23','0.18','0','50812','UAE','DWD') WHERE SPATA='UAE';
If I don't use the "WHERE", I get the "duplicate entries" error. If I DO use the "Where" statement, it tells me that WHERE was not expected. What am I doing wrong?
I want to be able to look at the parts in the database and, if a few key fields are the same (and the pricing code for that part already exists in the database), then update with the changes. If the part number is the same, but the pricing code field does NOT exist, I want it to insert a new entry, and copy all the matching information, with the new pricing code. How can I do this?
markros (Programmer)
8 May 12 13:51
What is your SQL Server version (assuming you're using SQL Server)?
In SQL Server 2008 and up you need to use MERGE statement similar to this

CODE

MERGE WebPrddT1.WBMSCur as target
USING (SELECT '3408320018' as SpptNo, 'PLASTIC SCREW' as SPDESC, etc) as source ON target.SPPTNo = source.SPPTNo and target.SPATA = source.SPATA
WHEN MATCHED THEN
  UPDATE
   SET SPDesc = source.SPDESC ...
WHEN NOT MATCHED THEN
  INSERT (...)
  values (source.SPPTNO, source.SPDESC, ...)

Please check the exact syntax in BOL as I wrote from the top of my head.
      

PluralSight Learning Library

dave3944 (Programmer)
8 May 12 13:55
I apologize for my ignorance, I am a newbie. I am using DB2 SQL going to an AS400 server database.  
markros (Programmer)
8 May 12 15:08
In this case I suggest to look for the correct forum for your question. This is SQL Server forum and you need a DB2 forum.

PluralSight Learning Library

Qik3Coder (Programmer)
8 May 12 18:42
dave3944,
While this is not a DB2 forum, the basic SQL rules apply.
You probably want something along the lines of:

INSERT INTO (...)
SELECT (...)
FROM WEBPRDDT1.WBMSCUR
WHERE (...)

Keep in mind you will want to INSERT WHERE a row doesn't exist.
You'll need to check the table for your particular set of requirements

Lodlaiden

You've got questions and source code. We want both!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close