Sql Syntax

Posted on 2010-01-12
Medium Priority
Last Modified: 2012-05-08
I need to copy data from an ExisitngID and Description values to a new ID and existing description. For instance
Existing records in a one to many table
ID     Desc
1       A
1       B
1       C
NewRecordID with the same values in Desc as above
NewID    Desc
4             A
4             B
4             C

I am tyring to pretty much clone the values from one ID to a new ID. Is there a better way of doing this without a cursor?

What I have in my proc so far is the developer passing me the ExistingID and the NewID and I have to fetch the ExistingID values and Insert them into the same table with the NewID
Question by:healthcheckinc
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
LVL 56

Accepted Solution

Bill Prew earned 2000 total points
ID: 26296045
You can do it all with one query if you know the new IDs will not be there yet.  Something like:

INSERT Table1 (ID, Desc)
FROM Table1

LVL 28

Expert Comment

ID: 26296079
You can do this in an INSERT query
Cheers, Andrew
INSERT INTO MyTable (ID, [Desc])
    , [Desc]
FROM MyTable

Open in new window


Author Closing Comment

ID: 31676263
thanks much

Featured Post

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

771 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