Link to home
Start Free TrialLog in
Avatar of StiggySon
StiggySon

asked on

Copy table row within same table and perform calculation

Hi to all,

I have a table and i will be making a copy of every row in the table based on a WHERE clause.  The new row that is being inserted is an exact duplicate of the original except for 3 columns.  2 of the columns called "large" and "small" take their values from a column called "ideal_value" for the new row being inserted "large" and "small" will be +- 10% of the "ideal_value" in the original row.  Is it possible to perform the calculation within the insert or what is the best way to to this.

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of Otana
Otana

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vitor Montalvão
Yes it is.
Should be something like this:

INSERT INTO NewTable (Col1, Col2, ..., ColN, Large, Small)
SELECT Col1, Col2, ..., ColN, Ideal_Value * 1.1, Ideal_Value * 0.9
FROM OriginalTable
WHERE MyCriteria
Avatar of StiggySon
StiggySon

ASKER

perfect, wasn't sure i could do that in the insert, thanks for the help.