Solved

cursor update + insert

Posted on 2013-01-29
6
366 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
  • 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
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

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…

760 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

18 Experts available now in Live!

Get 1:1 Help Now