Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy table row within same table and perform calculation

Posted on 2007-11-27
3
Medium Priority
?
550 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 2000 total points
ID: 20357381
That shouldn't be a problem.

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how the fundamental information of how to create a table.

704 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