Solved

Copy table row within same table and perform calculation

Posted on 2007-11-27
3
538 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:StiggySon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
Otana earned 500 total points
ID: 20357381
That shouldn't be a problem.

INSERT INTO Table
SELECT
  Field1, Field2 * Field3, Field3, ...
FROM Table
0
 
LVL 49

Expert Comment

by:Vitor Montalvão
ID: 20358161
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
0
 

Author Closing Comment

by:StiggySon
ID: 31411181
perfect, wasn't sure i could do that in the insert, thanks for the help.
0

Featured Post

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question