By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,191 Members | 2,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,191 IT Pros & Developers. It's quick & easy.

MS Excel /myodbc drops column aliases (with joined tables)

P: n/a
With command-line interface ( 3.23.37, UNIX Socket ) all is well with
column aliasing. However, column aliases disappear in Excel, over
ODBC, when there are multiple (joined) tables in the query.

I run the following query with aliased columns with CLI:

select table1.c1 as 'pet category', table1.c2 as 'item', table1.c3 as
'quantity', table2.c2 as 'attendant' from table1 left outer join
table2 on (table1.c1=table2.c1);
+--------------+--------+----------+------------+
| pet category | item | quantity | attendant |
+--------------+--------+----------+------------+
| dog | leash | 3 | Dan Miller |
| cat | collar | 5 | Kim Sloan |
| dog | collar | 4 | Dan Miller |
+--------------+--------+----------+------------+
3 rows in set (0.00 sec)

and all is well. The table1.c1 column is labeled as 'pet category',
table1.c2 as 'item', etc., etc.

But executing this same query in Excel ODBC my labels revert to the
original column names, and the aliases "peth category", "item",
....etc, are ignored:
c1 c2 c3 c2

Interestingly, though, Excel/MyODBC _retains_ column aliases for
single-table queries.

Is there some setting that can correct this? My
Edit->Options->"Qualify table names in SQL statement" box is grayed
out. So is the "Prodedures" button in the File->Execute SQL dialogue.

This phenomenon occurs in many versions of Excel, including 2000 and
97.

Thanks!

andrew
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
After posting my message (quoted here) I discovered a case where Excel
drops the column alias with one table in the query. My query is

select schools.*, if( sid between 5000 and 6000, 1, 0) as 'do'
from schools
order by do, dist, name

Please note the "do" alias and the IF statement column it represents.
In this column a row is qualified (with either 1 or 0), based on the
IF condition, then the value is used in one of the sort levels (the
first one). The "order by" syntax lets you use the alias you've set
in the select clause...

I was happy to discover that aliases can be more than cosmetic - that
they can be as functional as allowing a sort otherwise impossible
(impossible without the alias).

And now I am suffering from this Excel alias omission problem where,
for a query such as above, the aliases get erased, and Excel tells me
"unknown column 'do' in order clause", after having wiped that which
it complains it can't find, from the select clause. Frustrating!

Any ideas?
thanks in advance


se*****@scssi.org (Andrew) wrote in message news:<a8**************************@posting.google. com>...
With command-line interface ( 3.23.37, UNIX Socket ) all is well with
column aliasing. However, column aliases disappear in Excel, over
ODBC, when there are multiple (joined) tables in the query.

I run the following query with aliased columns with CLI:

select table1.c1 as 'pet category', table1.c2 as 'item', table1.c3 as
'quantity', table2.c2 as 'attendant' from table1 left outer join
table2 on (table1.c1=table2.c1);
+--------------+--------+----------+------------+
| pet category | item | quantity | attendant |
+--------------+--------+----------+------------+
| dog | leash | 3 | Dan Miller |
| cat | collar | 5 | Kim Sloan |
| dog | collar | 4 | Dan Miller |
+--------------+--------+----------+------------+
3 rows in set (0.00 sec)

and all is well. The table1.c1 column is labeled as 'pet category',
table1.c2 as 'item', etc., etc.

But executing this same query in Excel ODBC my labels revert to the
original column names, and the aliases "peth category", "item",
...etc, are ignored:
c1 c2 c3 c2

Interestingly, though, Excel/MyODBC _retains_ column aliases for
single-table queries.

Is there some setting that can correct this? My
Edit->Options->"Qualify table names in SQL statement" box is grayed
out. So is the "Prodedures" button in the File->Execute SQL dialogue.

This phenomenon occurs in many versions of Excel, including 2000 and
97.

Thanks!

andrew

Jul 19 '05 #2

P: n/a
After posting my message (quoted here) I discovered a case where Excel
drops the column alias with one table in the query. My query is

select schools.*, if( sid between 5000 and 6000, 1, 0) as 'do'
from schools
order by do, dist, name

Please note the "do" alias and the IF statement column it represents.
In this column a row is qualified (with either 1 or 0), based on the
IF condition, then the value is used in one of the sort levels (the
first one). The "order by" syntax lets you use the alias you've set
in the select clause...

I was happy to discover that aliases can be more than cosmetic - that
they can be as functional as allowing a sort otherwise impossible
(impossible without the alias).

And now I am suffering from this Excel alias omission problem where,
for a query such as above, the aliases get erased, and Excel tells me
"unknown column 'do' in order clause", after having wiped that which
it complains it can't find, from the select clause. Frustrating!

Any ideas?
thanks in advance


se*****@scssi.org (Andrew) wrote in message news:<a8**************************@posting.google. com>...
With command-line interface ( 3.23.37, UNIX Socket ) all is well with
column aliasing. However, column aliases disappear in Excel, over
ODBC, when there are multiple (joined) tables in the query.

I run the following query with aliased columns with CLI:

select table1.c1 as 'pet category', table1.c2 as 'item', table1.c3 as
'quantity', table2.c2 as 'attendant' from table1 left outer join
table2 on (table1.c1=table2.c1);
+--------------+--------+----------+------------+
| pet category | item | quantity | attendant |
+--------------+--------+----------+------------+
| dog | leash | 3 | Dan Miller |
| cat | collar | 5 | Kim Sloan |
| dog | collar | 4 | Dan Miller |
+--------------+--------+----------+------------+
3 rows in set (0.00 sec)

and all is well. The table1.c1 column is labeled as 'pet category',
table1.c2 as 'item', etc., etc.

But executing this same query in Excel ODBC my labels revert to the
original column names, and the aliases "peth category", "item",
...etc, are ignored:
c1 c2 c3 c2

Interestingly, though, Excel/MyODBC _retains_ column aliases for
single-table queries.

Is there some setting that can correct this? My
Edit->Options->"Qualify table names in SQL statement" box is grayed
out. So is the "Prodedures" button in the File->Execute SQL dialogue.

This phenomenon occurs in many versions of Excel, including 2000 and
97.

Thanks!

andrew

Jul 19 '05 #3

P: n/a
After posting my message (quoted here) I discovered a case where Excel
drops the column alias with one table in the query. My query is

select schools.*, if( sid between 5000 and 6000, 1, 0) as 'do'
from schools
order by do, dist, name

Please note the "do" alias and the IF statement column it represents.
In this column a row is qualified (with either 1 or 0), based on the
IF condition, then the value is used in one of the sort levels (the
first one). The "order by" syntax lets you use the alias you've set
in the select clause...

I was happy to discover that aliases can be more than cosmetic - that
they can be as functional as allowing a sort otherwise impossible
(impossible without the alias).

And now I am suffering from this Excel alias omission problem where,
for a query such as above, the aliases get erased, and Excel tells me
"unknown column 'do' in order clause", after having wiped that which
it complains it can't find, from the select clause. Frustrating!

Any ideas?
thanks in advance


se*****@scssi.org (Andrew) wrote in message news:<a8**************************@posting.google. com>...
With command-line interface ( 3.23.37, UNIX Socket ) all is well with
column aliasing. However, column aliases disappear in Excel, over
ODBC, when there are multiple (joined) tables in the query.

I run the following query with aliased columns with CLI:

select table1.c1 as 'pet category', table1.c2 as 'item', table1.c3 as
'quantity', table2.c2 as 'attendant' from table1 left outer join
table2 on (table1.c1=table2.c1);
+--------------+--------+----------+------------+
| pet category | item | quantity | attendant |
+--------------+--------+----------+------------+
| dog | leash | 3 | Dan Miller |
| cat | collar | 5 | Kim Sloan |
| dog | collar | 4 | Dan Miller |
+--------------+--------+----------+------------+
3 rows in set (0.00 sec)

and all is well. The table1.c1 column is labeled as 'pet category',
table1.c2 as 'item', etc., etc.

But executing this same query in Excel ODBC my labels revert to the
original column names, and the aliases "peth category", "item",
...etc, are ignored:
c1 c2 c3 c2

Interestingly, though, Excel/MyODBC _retains_ column aliases for
single-table queries.

Is there some setting that can correct this? My
Edit->Options->"Qualify table names in SQL statement" box is grayed
out. So is the "Prodedures" button in the File->Execute SQL dialogue.

This phenomenon occurs in many versions of Excel, including 2000 and
97.

Thanks!

andrew

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.