Solved

cursor update + insert

Posted on 2013-01-29
6
373 Views
Last Modified: 2013-01-29
hello guys,

I have a question, I have two tables with exactly the same settings example:


table1
NAME, AGE, DATE, IDENTIFIER, PHONE

table2
NAME, AGE, DATE, IDENTIFIER, PHONE

Table 1 is updated every day and I need to mount a cursor to read the record and compare to table2 record if they match make an update in table2 with data from table1.

if you have data in table1 in table2 that do not have an insert in table2 as I assemble this structure?
0
Comment
Question by:eduardo12fox
[X]
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
  • 4
6 Comments
 
LVL 14

Assisted Solution

by:Emes
Emes earned 250 total points
ID: 38831820
Try to use this

insert into table2
select NAME, AGE, DATE, IDENTIFIER, PHONE
FROM   table1
WHERE  NOT EXISTS
  (SELECT NAME, AGE, DATE, IDENTIFIER, PHONE
   FROM   table2
   WHERE  table2.NAME = table1.Name
and table2.Age = table1.age

and table2.date = table1.date
and table2.IDENTIFIER = table1.IDENTIFIER
and table2.PHONE = table1.Phone)
0
 
LVL 1

Accepted Solution

by:
DoutorApedeuta earned 250 total points
ID: 38831852
Hi,

Do you really need that cursor. I think you could easily solve the problem using this sintax:

insert into t1(a, b, c)
    select d, e, f from t2
    on duplicate key update b = e, c = f;

This, of course, assuming that there are unique keys in the tables.

Check this article for more info.
0
 

Author Comment

by:eduardo12fox
ID: 38831861
Fantastico! The insert was perfect but I can not implement UPDATE
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:eduardo12fox
ID: 38831869
Ok ok but to insert and find lines like how when I update the same line without the insert?
0
 

Author Comment

by:eduardo12fox
ID: 38831888
OK! Fantastico was correct and helped me a lot. I want to thank everyone's attention. Thank you!!
0
 

Author Closing Comment

by:eduardo12fox
ID: 38831892
OK! Fantastico was correct and helped me a lot. I want to thank everyone's attention. Thank you!!
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

697 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