Solved

Store Procedure....

Posted on 1998-08-19
4
203 Views
Last Modified: 2010-03-19
How do I create a stored procedure to copy the contents
of one table (with a where statement on a field) to another
table that already exist and MAY have data in it already that we can't kill?
0
Comment
Question by:ohayden
[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 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1089640
Do the tables have the same format?
0
 
LVL 4

Expert Comment

by:mitek
ID: 1089641
Something like that:

INSERT INTO tab1
  SELECT c1,c2,c3 FROM tab2 -- select only those columns that will match the columns of the first table
   WHERE c1 = 'NY' -- any condition

If that's notwhat you meant, please rephrase your question
(as someone noticed, a well asked question already contains 1/2 of answer :)

0
 
LVL 3

Accepted Solution

by:
gmoriak earned 50 total points
ID: 1089642
Here's all scenarios I can think of

/* insert all rows no matter what */
Insert A (pkCol, col2, col3)
(select B.pkCol, B.col2, B.col3
 from B)

/* insert on rows in B not existing in A */
Insert A (pkCol, col2, col3)
(select B.pkCol, B.col2, B.col3
 from B
 where not exists (select A2.pkCol from A2 where A2.pkCol = B.pkCol)


0
 

Author Comment

by:ohayden
ID: 1089643
I already solved the problem but your answer was exactly how I did it, so even though I did use your answer the points are yours..... thanks.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

636 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