Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Sql Syntax

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
0
healthcheckinc
Asked:
healthcheckinc
1 Solution
 
Bill PrewCommented:
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)
SELECT @NewID, Desc
FROM Table1
WHERE ID = @OldID

~bp
0
 
TextReportCommented:
You can do this in an INSERT query
Cheers, Andrew
INSERT INTO MyTable (ID, [Desc])
SELECT 4 AS ID
    , [Desc]
FROM MyTable
WHERE ID=1

Open in new window

0
 
healthcheckincAuthor Commented:
thanks much
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now