Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How can I manage multitle columns with the same na

Author  Topic 

rasael
Starting Member

2 Posts

Posted - 2007-03-21 : 18:41:35

Hi folks!
I have this simple but hard-to-find-a-solution problem with SQL server.
During a SELECT query I create a relation between many tables that have a common column name (for example "name").

When I retrieve the data I cannot see any kind of distinction between the columns, I would like to have my result as table1.name , table2.name .

I cannot change the column names and cannot even set the AS parameter for every column...(they are too much)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-03-21 : 18:50:20
Why can't you use AS? Are you just being lazy?

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-21 : 18:56:37
you don't have to use the AS for every column only for common column name.


KH

Go to Top of Page

rasael
Starting Member

2 Posts

Posted - 2007-03-21 : 19:01:13
Wow super fast answer! I just findout how to use AS :) I tought I had to use AS on every column!!

then the solution is SELECT tab1.name AS tab1name, tab2.name AS tab2name, * FROM tab1, tab2, tab3 WHERE ...

Anyway thanks, I looked out on the web for hours and didn't find anything
Go to Top of Page

JMBeyer
Starting Member

1 Post

Posted - 2007-03-22 : 11:20:51
You can also qualify your names:

SELECT ORD.NAME, CUS.NAME
FROM ORDERS ORD, CUSTOMERS CUS
WHERE ORD.USER_ID = CUS.USER_ID

or if you want to be more verbose:

SELECT ORDERS.NAME, CUSTOMERS.NAME
FROM ORDERS, CUSTOMERS
WHERE ORDERS.USER_ID = CUSTOMERS.USER_ID
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-22 : 19:31:53
quote:
Originally posted by JMBeyer

You can also qualify your names:

SELECT ORD.NAME, CUS.NAME
FROM ORDERS ORD, CUSTOMERS CUS
WHERE ORD.USER_ID = CUS.USER_ID

or if you want to be more verbose:

SELECT ORDERS.NAME, CUSTOMERS.NAME
FROM ORDERS, CUSTOMERS
WHERE ORDERS.USER_ID = CUSTOMERS.USER_ID



You will still need to alias the column as to the front end it is still appearing as 2 columns of NAME.

SELECT ORD.NAME as ORDER_NAME, CUS.NAME as CUST_NAME
FROM ORDERS ORD, CUSTOMERS CUS
WHERE ORD.USER_ID = CUS.USER_ID



KH

Go to Top of Page
   

- Advertisement -