Solved

Store Procedure....

Posted on 1998-08-19
4
196 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
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

758 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

21 Experts available now in Live!

Get 1:1 Help Now