MainTable and SubTable have a lot of columns.
SELECT Sub.*, Main.* FROM
(
SELECT * FROM [SubTable]
) Sub
LEFT OUTER JOIN [MainTable] main
ON Sub.MainID = Main.ID
This query returns every column of every table.
Some of the columns in SubTable have the same name as some in the MainTable f.e. created or modified and lots of other ones.
Is there a way in SQL Server to do something like (without listing every column):
Select Sub.* as sub_[subcolumnname], Main.* as main_[columnname]
its hard for me finding a term for what I want, which makes it nearly impossible to google it.
Any advice is welcome, thanks in advance
You can do this kind of thing only with dynamic sql: http://www.techrepublic.com/blog/datacenter/generate-dynamic-sql-statements-in-sql-server/306