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 |
|
giviglie
Starting Member
5 Posts |
Posted - 2009-01-07 : 07:43:08
|
| Hi...I will try to explain my problem. I have 2 to tables.In the first table I have 2 colums: ID (int primary key), MyDate (DateTime).In the second Table for now I save in a DateTime column the MyDate value from the first table.Now I was asked to save not the date but the ID from the first table in a new column in Table 2 called IDMyDate.All the tables already contain records.My boss asked me to create a script that populates the Table2.IDMyDate Column with the right ID from Table1. So I had never done a stuff like this and I am in a really big trouble.Any suggestion will be very appreciated!ThanxGiacomo |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-01-07 : 07:47:49
|
| Update fkset fk.idmydate = pk.idfrom primarykeytable pk inner join foreignkeytable fk on fk.commoncolumn = pk.commoncolumnor justupdate foreignkeytable set idmydate = idwhat is the need of two columns containing same values |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-07 : 10:08:02
|
| [code]Update t2set t2.idmydate = t1.idfrom table1 t1inner join table2 t2on t2.DateColumn= t1.MyDate[/code] |
 |
|
|
|
|
|