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 |
|
JasonShave
Starting Member
2 Posts |
Posted - 2005-11-21 : 21:43:11
|
Greetings,I'm trying to calculate two "Quantity" values from different databases and create a third table with these values. Does anyone know how to write this in T-SQL?All databases are identical in structure.Database1=edmdb, Table=Item, Value=QuantityDatabase2=whsdb, Table=Item, Value=QuantityDatabase3=webdb, Table=tblItem, Value=WebQuantityThe WebQuantity should be the sum of both quantity values from db1 and db2.Thanks in advance! I'm lost!! |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-11-21 : 21:58:53
|
| insert tblItem (item_id, WebQuantity)select edmdb.item_id, edmdb_Item.Quantity + whsdb_Item.Quantityfrom edmdb.dbo.Item edmdb_Itemjoin whsdb.dbo.Item whsdb_Itemon edmdb_Item.item_id = whsdb_Item.item_idI'm guessing about the item_id but you'll get the idea.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
JasonShave
Starting Member
2 Posts |
Posted - 2005-11-21 : 22:01:15
|
| great! thanks. so you don't need to specify the "use" statement when working with different databases? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-22 : 00:54:32
|
quote: Originally posted by JasonShave great! thanks. so you don't need to specify the "use" statement when working with different databases?
YesAlso Usage of USE is not allowed inside a stored ProcedureMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|