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
 append and update at same time?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

newbie123
Starting Member

2 Posts

Posted - 08/13/2012 :  12:33:52  Show Profile  Reply with Quote
Table Name: Relation
Data:
ID ID1 ID2
1 602 5
1 602 402
1 602 403
1 602 407
1 602 491
1 602 492
1 602 493
2 602 2
2 602 402
2 602 403
2 602 407
2 602 491
2 602 492
2 602 493
...

What I would like to do is append the following data to the same table , they are same as those record with ID=2, the only difference is ID=3
3 602 2
3 602 402
3 602 403
3 602 407
3 602 491
3 602 492
3 602 493

Is there a SQL statement can achieve that? I tried insert into and update but not successful.

Appreciate for any help :)
newbie

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 08/13/2012 :  12:42:33  Show Profile  Reply with Quote
Run the parts starting at SELECT in the following first. That will show you exactly what is going to be inserted into the table. Then if you are satisfied, run the whole statement:
INSERT INTO Relation
SELECT
	3 AS ID,
	ID1,
	ID2
FROM
	Relation
WHERE
	ID = 2;
Go to Top of Page

newbie123
Starting Member

2 Posts

Posted - 08/13/2012 :  13:59:44  Show Profile  Reply with Quote
Works, thx!
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.23 seconds. Powered By: Snitz Forums 2000