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
 Transact-SQL (2000)
 How to name a column that is result from a subquer

Author  Topic 

eurob
Posting Yak Master

100 Posts

Posted - 2005-08-12 : 14:19:48
How do I get a column name for the subquery result ?

select distinct(myclient),
(select sum(myvalue) from mytable m
where cycleid = 31 and reportid = 1
and m.clientid = m1.clientid) <--- How do I name subquery ?

from mysecondtable m1
inner join reportnames n on n.reportid = m1.reportid
where a=b
group by clientid

thanks,

robert

robert

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-08-12 : 14:43:08
Use AS after the end of the query.

Tara
Go to Top of Page

ajthepoolman
Constraint Violating Yak Guru

384 Posts

Posted - 2005-08-12 : 14:44:55
select distinct(myclient) AS [Client],
(select sum(myvalue) from mytable m
where cycleid = 31 and reportid = 1
and m.clientid = m1.clientid) AS [SUM] <--- How do I name subquery ?
from mysecondtable m1
inner join reportnames n on n.reportid = m1.reportid
where a=b
group by clientid

Is that what you need, or is this more what you were thinking:

select
[Client] = distinct(myclient),
[SumAmount] = (select sum(myvalue) from mytable m
where cycleid = 31 and reportid = 1
and m.clientid = m1.clientid) <--- How do I name subquery ?
from mysecondtable m1
inner join reportnames n on n.reportid = m1.reportid
where a=b
group by clientid

Aj

Hey, it compiles.
Go to Top of Page

eurob
Posting Yak Master

100 Posts

Posted - 2005-08-12 : 14:53:11
Thanks, it worked.

robert

robert
Go to Top of Page
   

- Advertisement -