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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect, wasn't sure i could do that in the insert, thanks for the help.
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