Solved

Copy table row within same table and perform calculation

Posted on 2007-11-27
3
504 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 45

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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

760 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

20 Experts available now in Live!

Get 1:1 Help Now