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 |
|
Fatkitty
Starting Member
2 Posts |
Posted - 2005-10-06 : 05:52:46
|
| I am trying to copy item names from one database to another if they share the same code number.e.g.UPDATE TABLE1SET NAME = DB2.TABLE2.NAMEWHERE CODE = DB2.TABLE2.CODEI dont know how to specify the second db as using a '.' here doesnt seem to work. I have also tried '..' and DB2.dbo.TABLE2 but get the same error - 'The column prefix 'Train_DB_FinancialsProd.dbo.ITEM_DEFINITIONS' does not match with a table name or alias name used in the query.'I have checked that the spelling is ok so not sure why it doesnt work.I have also tried using a temp db in between to copy the values across then try to update from the temp table but couldnt make that work either. e.g.create table #tdhname( code char(50), name char(100))INSERT INTO #tdhname (code,name) select distinct code,name from Train_DB_FinancialsProd..item_definitions tritm where code = tritm.code and tritm.ittyp_refno = 241update pharmacy_itemsset name = #tdhname.name <----- THIS DOESNT WORKwhere #tdhname.code = codeThanks! |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2005-10-06 : 05:58:50
|
UPDATE TABLE1SET NAME = b.NameFROM Table1 aINNER JOIN DB2.dbo.TABLE2 bON a.CODE = b.CODEDuane. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-06 : 06:02:49
|
| Try thisupdate P set name = T.name from pharmacy_items P inner join #tdhname.name T on P.code = T.codeMadhivananFailing to plan is Planning to fail |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2005-10-06 : 06:08:59
|
quote: Originally posted by madhivanan update P set name = T.name from pharmacy_items P inner join #tdhname.name T on P.code = T.code
why use the temp tables when you can update straight from the physical tables?Duane. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-06 : 06:12:35
|
Correct MadhivananFailing to plan is Planning to fail |
 |
|
|
Fatkitty
Starting Member
2 Posts |
Posted - 2005-10-06 : 06:18:44
|
| Thanks, using the inner join worked!Im not too hot on joins yet but am learning.many thanks again! |
 |
|
|
|
|
|