Solved

cursor update + insert

Posted on 2013-01-29
6
374 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

691 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