0

I have inserted 9000 rows into the AcctHist table in the database. The LedgerID is 'HOME'. Now I need to copy these rows and insert them again into the same table, but with LedgedID = 'FIELD' (LedgerID is part of the Primary key). No other changes.

How can I achieve this ? Do I need to copy this data to excel, make the changes and then insert again?

2
  • Are there any other rows in AccHist with a LedgerID = 'HOME? Commented Dec 11, 2013 at 18:00
  • Yes, that is what I inserted. Now I have to copy all these rows with ledgerId = 'HOME' and insert it again into the same table, but with ledgerID ='FIELD' Commented Dec 11, 2013 at 18:03

1 Answer 1

3

Given that all rows with LedgerID = 'HOME' are the ones you inserted and the ones you need copied, this should work, swapping out <all other columns in AcctHist, comma delimited> with your actual column names. Note that if you have any identity fields, you should omit those, since they will be populated automatically.

INSERT INTO AcctHist ( LedgerID, <all other columns in AcctHist, comma delimited> ) SELECT 'FIELD', <all other columns in AcctHist, comma delimited> FROM AcctHist WHERE LedgerID = 'HOME' 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.