I am trying to copy multiple records using one query using insert select from.
Insert into tab_A(colId, col1, col2, col3)
Select colId, col1, col2, col3 form tab_A
Where colId in ( 2,4,6)
Would it be possible to assign different colId for new entries? For example colid 2 should be replaced with 23, 4 with 24 and 6 with 25. How could I achieve it in a single query?
this would work
If you give some more info I could provide somthing more reusable. Should/is
colId(be) an identity column?EDIT
This would work in this very specialised case
The function
newId = ((oldId - 4) * (-1)) + oldId + 20is obviously specific to the stated problem.EDIT2
I suspect somthing like this is more generic approach is appropriate.
EDIT 3
If you think EDIT 2 is actually what you want then you really want to make
ColIDanIDENTITYcolumn, then you could do this.