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)
 select different fields from different views

Author  Topic 

Teachme
Starting Member

45 Posts

Posted - 2006-10-12 : 14:28:25
i was wondering if its possbile that i can select multiple columns from a view into one column. For instance i have viewA, viewB, viewC and all the three views have a computed sum column. I need to create another view to have only one column with all the sum values from the above views. Any kind of help would be appreciated. Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-12 : 14:32:10
is this what you want ?

select col = a.cola + b.colb + c.colc
from viewa a inner join viewb b
on a.somecol = b.somecol
inner join viewc c
on a.somecol = c.somecol



KH

Go to Top of Page

Teachme
Starting Member

45 Posts

Posted - 2006-10-12 : 14:44:09
no..something like this viewA has a column say gain and values are(5,10,7) 3 records..viewB has a column gain and values (35,76,89,70) i want to be able to take those 2 columns and come up with something like this:
newView(with only one column)
5
10
7
35
76
89
70
Go to Top of Page

Teachme
Starting Member

45 Posts

Posted - 2006-10-12 : 14:51:13
i know i can use union..but the scenario i have is much more complicted and lots of views and columns..anyway thanks
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-10-12 : 15:10:50
UNION is the correct DML for what you describe. In the spirit of "Teaching You", go ahead and post your "much more complicated" situation and maybe someone can ...

Jay White
Go to Top of Page

Teachme
Starting Member

45 Posts

Posted - 2006-10-12 : 15:31:49
so how can i combine these 2 union clauese so that it gives me 2 columns with 2 records in each or in other words i gota make a view out of which shud give give me 2 columns with 2 records in it..any thoughts?

select tot_book_val from vw_schedule_1_sum
union
select tot_book_val from vw_schedule_2_sum as s2sum

select tot_market_val_cur from vw_schedule_4a_sum
union
select grand_tot_end_market_val from vw_schedule5_grandtotal
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-10-12 : 17:23:34
You are going to need to post some DDL and some DML to insert some sample data for me to get involved. I can't quite make out what you are trying to do, but I suspect your are about a mile down the wrong road ...

Jay White
Go to Top of Page

Teachme
Starting Member

45 Posts

Posted - 2006-10-13 : 10:10:47
thanks for the effort..i was able to figure it out..i need to use table variable..i got it...thanks..TC
Go to Top of Page

Teachme
Starting Member

45 Posts

Posted - 2006-10-13 : 10:10:51
thanks for the effort..i was able to figure it out..i need to use table variable..i got it...thanks..TC
Go to Top of Page
   

- Advertisement -