Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert rows in new from old table with modificatio

Author  Topic 

Marko299
Starting Member

6 Posts

Posted - 2012-07-14 : 10:29:00
Lets say i have created new table and it is empty.

I have to insert values from old with modifications.

create table #NewTable(v1, v2, v3, v4);
create table OldTable(vo1, vo2, vo3, vo4);

After inserting it should be for example;

v1=vo2/5;
v2=vo4/3;
...


sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-07-14 : 10:45:48
[code]INSERT INTO #NewTable
(v1, v2, v3, v4)
SELECT
vo2/5,
vo5/3,
v3,
v4
FROM
OldTable;[/code]
Go to Top of Page

Marko299
Starting Member

6 Posts

Posted - 2012-07-14 : 11:25:18
Thanks, it works. :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-14 : 19:51:54
make sure you use like below if vo,vo2 are int and you want decimal part also in result

INSERT INTO #NewTable
(v1, v2, v3, v4)
SELECT
vo2/5.0,
vo5/3.0,
v3,
v4
FROM
OldTable;


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -