SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert rows in new from old table with modificatio
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Marko299
Starting Member

6 Posts

Posted - 07/14/2012 :  10:29:00  Show Profile  Reply with Quote
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;
...



Edited by - Marko299 on 07/14/2012 10:38:00

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

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

Marko299
Starting Member

6 Posts

Posted - 07/14/2012 :  11:25:18  Show Profile  Reply with Quote
Thanks, it works. :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 07/14/2012 :  19:51:54  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.48 seconds. Powered By: Snitz Forums 2000