I'm looking to refactor the below query to something more readable and modifiable. The first half is identical to the second, with the exception of the database queried from (table names are the same though.)
SELECT
Column 1 AS c1,
...
Column N AS cN
FROM
database1.dbo.Table1
UNION
SELECT
'Some String' as c1,
...
NULL as cN
FROM
database1.dbo.Table2
UNION
SELECT
Column 1 AS c1,
...
Column N AS cN
FROM
database2.dbo.Table1
UNION
SELECT
'Some String' as c1,
...
NULL as cN
FROM
database2.dbo.Table2
This query is the definition of DRY and is calling to me to be re-written, but I have no idea how!
EDIT: We can't use linq and we desire distinct results; I'm looking to make the query smaller in physical file size, not in results returned.
EDIT: The database I'm querying off is a proprietary ERP database. Restructuring it is not an option.