How do I select from multiple tables in different databases on the same server?
Also, Is there a way to have an identifying marker so I could see where the results came
You could use a UNION ALL and add in the database name like:
SELECT [columns_list], 'db1.schema.table1.name' AS [fromTbl]
FROM db1.schema.table1
WHERE db1.schema.table1.name LIKE '%j%'
UNION ALL
SELECT [columns_list], 'db2.schema.table2.name' AS [fromTbl]
FROM db2.schema.table2
WHERE db2.schema.table2.name LIKE '%j%'
This will only work if the columns in the tables have the same column types (as your example suggests) else UNION will not work.
Doing a union seems like your best bet here. A union will combine the results of two queries.
select name, 'table1' as fromTbl
from db1.schema.table1
where name like '%j%'
union --or union all depending on what you want
select name, 'table2' as fromTbl
from db2.schema.table2
where name like '%j%'
try this: SELECT * FROM OPENROWSET('SQLNCLI', 'Server=YOUR SERVER;Trusted_Connection=yes;','SELECT * FROM Table1') AS a UNION SELECT * FROM OPENROWSET('SQLNCLI', 'Server=ANOTHER SERVER;Trusted_Connection=yes;','SELECT * FROM Table1') AS a