Data Retrieval Via SQL

Job ID: 37829830

Budget: $30 – $250 AUD

I'm in need of an expert to construct SQL statements that will retrieve specific data from a database.

I have an SQL Server with multiple databases, with existing SQL query that looks similar to

Select * from DataBase1.User
union all
Select * from DataBase2.User
union all
Select * from Database3.User

The select command is a lot more advanced than a simple Select *, but I need to be able to easily extend and included more databases, without having to cut, copy, paste, then perform a find and replace of the database tables.

If i was to write in DOS, it would be something like

for each %i in ( Database1, Database2, Database 3){
select * from %1.user
union all
}

but just not sure the best way to do this in SQL, and looking quick assistance.

thanks
Related categories: SQL Microsoft SQL Server