Question Locked

Help! How toQuery 2 SQL Databases for same data with different field names

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
What statement can I write to query 2 sql databases with different field names but same business data? I would like to know the name of the fields the same information is pulling from in both tables. I will also be using sql 2005.

2 replies

by tony hopkinson

pull data from a different database on the same server.

Select * From DatabaseName..TableName

The user you are connected as needs to authorised in both DBs. Generally you are better off connecting with your windows login than using sql server ones other than sa.

To 'merge' the columns of two tables you do something like this

Select Column1, Column2 From Table1
UNION
Select Col1,Col2 From Table2

Column1 and Column2 will be the fieldnames in the result.

If that gets messay then you can do something like this

Select Column1 As MyNewColumn1, Column2 as MyNewColumn2 From Table1
UNION
Select Col1,Col2 From Table2

HtHs

This discussion is closed to new replies.