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)
 columns with the same name in one table

Author  Topic 

misterjane
Starting Member

1 Post

Posted - 2008-05-12 : 07:05:01
Hi,

I have a table (that i get as a result of pivots and joins in a stored procedure) that has two columns with the same name, (each time the stored procedure is called, different columns will be in this situation). For every row, only one of these columns has a value and the other has NULL.

Does anyone know how to do prevent this situation during the JOIN that creates this table? OR of a way to merge these columns once they are there ?

Thanks !!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-12 : 07:09:46
Use a column alias in you statement where you create the table using pivot/join. If you can post the query used, we will be able to provide you with more specific answer.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-12 : 07:11:25
Make use of IsNull or Coalesce() function.

SELECT Coalesce(table1.col1, table2.col1) as col1
from table1 join table2 on...


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -