all groups > sql server new users > december 2004 >
You're in the

sql server new users

group:

Table names in result set


Table names in result set Christoph
12/15/2004 3:46:26 PM
sql server new users:
Is there a way to get it so that the columns in a result set
are preceded with the table name that column belongs do?
Without manually aliasing each column?
Right now, if I run the following query:

select table1.*, table2.* from table1, table2;

it only shows the column names. For example, it would
only show:

col1 | col2 | col3 | col4

I'm wondering if there is a way so that the column names
that get returned are as such:

table1.col1 | table1.col2 | table2.col3 | table2.col4

thnx,
Christoph

Re: Table names in result set David Portas
12/15/2004 11:17:45 PM
There is no automatic method in SQL. Some client tools may do this for you
but that depends on what client application you are using.

Note that there are good reasons to avoid using * in the SELECT list of a
query. It's OK for ad-hoc queries but you should avoid doing so in actual
production code. List the column names instead.

--
David Portas
SQL Server MVP
--

AddThis Social Bookmark Button