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.
| Author |
Topic |
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2009-03-04 : 12:05:35
|
| There are two tables: Order1 and Order2.How to code to insert all records from Order1 to Order2 but keep OrderID and ProductID both are unique in Order2?That is, OrderID only list one time and ProductID only list one time as well. If a OrderID has more than one ProductID, can only list one ProductID. |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-03-04 : 12:14:14
|
| try some thing like thisinsert into order2select t.col1,t.col2,...,t.coln from ( select row_number() over ( partition by orderid,productid order by orderid,productid ) as sno, col1,col2,...,colnfrom order1 ) twhere t.sno = 1 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-04 : 12:47:11
|
quote: Originally posted by raky try some thing like thisinsert into order2select t.col1,t.col2,...,t.coln from ( select row_number() over ( partition by orderid,productid order by orderid, productid ) as sno, col1,col2,...,colnfrom order1 ) twhere t.sno = 1
it seems op needs only one record per orderid, so modify as above |
 |
|
|
|
|
|
|
|