Simple way to join many tables with similar names in SSMS?

I have many tables that are all named similarly (like "table1" "table2" "table3" etc.) and I need to use all of them in a query. They all contain the same two variables ("ID" and "date") that they are joined on.

There are at least 25 tables of this sort and I have read-only access to the database so I can't combine them or even create a view that would do so.

My question is: Is there a simple shortcut I can use to join all these tables? If this were SAS I would create a macro, but I'm using Microsoft SQL Server Management Studio 2012.

Instead of having to do this:

 select *   from table1 a  join table2 b on and  join table3 c on and  join ....  join ....  join table25 y on and 

I'd like to do something like:

 select *  from merge(table1 - table25) using(name, date) 

Replacing the "merge" statement above with whatever is appropriate. Is such a thing possible?


Category: sql Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.114 (s). 12 q(s)