SELECTing from two database | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

SELECTing from two database

INSERT INTO MyBooks
SELECT title_id, title, type
FROM titles
WHERE type = ‘mod_cook’ IF MyBooks is from DB1 and Titles is in DB2 how would I do this? (This is wrong!!!, but something like this):
INSERT INTO DB1.MyBooks
SELECT DB2.title_id, title, type
FROM titles
WHERE type = ‘mod_cook’ Thanks!
When you want to get data from another database, you need to use the following format: database.owner.tablename so something like this should work (if run from DB1) INSERT INTO MyBooks
SELECT title_id, title, type
FROM DB2.dbo.titles
WHERE type = ‘mod_cook’ Ben
]]>