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 2000 Forums
 SQL Server Development (2000)
 add column to joined query

Author  Topic 

cjhardie
Yak Posting Veteran

58 Posts

Posted - 2006-09-14 : 10:23:58
How do I add a column to a query that is already has joins in it.
I dont know what to put after ALTER TABLE becuase the table has no name??

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-14 : 10:28:39
quote:
How do I add a column to a query that is already has joins in it.


Do you want to add column in join condition or display it?

quote:
I dont know what to put after ALTER TABLE becuase the table has no name??

What alter table has to do with join? Table has no name...Can anybody tell me what this guy is talking about?

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

cjhardie
Yak Posting Veteran

58 Posts

Posted - 2006-09-14 : 10:31:56
after doing all of my joins i would like to add a new column to the results, because the results are from multiple tables there is no name for the table.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-14 : 10:49:49
If you wish to add an empty column to the resultset created from the output of join query, you can do like this:

Select t1.Col1, t2.col2, convert(varchar(10),'') as NewCol
From Tbl1 t1
Join Tbl2 t2 on t1.id = t2.id

Of course, this example shows how to add varchar(10) column, if you want to add numeric or int column, make appropriate changes.


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -