Solved

Copy table row within same table and perform calculation

Posted on 2007-11-27
3
515 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
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 46

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now