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 to fix the problem with this code?

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2008-01-11 : 17:22:44
SELECT B.Date,
(Select sum(datediff(day, firstfundingdate,b.date)*fundedamount)/sum(fundedamount)
from #dqall where dqstartdate<=B.date
and (dqenddate>B.date or dqenddate is null)
) as wgtage
FROM
(
SELECT DISTINCT
DATEADD(DAY, number, '11/1/2005') AS Date
FROM
Master.dbo.spt_values
WHERE
number between 0 AND DATEDIFF(DAY, '11/1/2005', '1/9/2006')
) AS B

error msg:
Server: Msg 8124, Level 16, State 1, Line 1
Multiple columns are specified in an aggregated expression containing an outer reference. If an expression being aggregated contains an outer reference, then that outer reference must be the only column referenced in the expression.

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-01-11 : 18:03:15
[code]
Select dateadd(day,m.number,'11/1/2005'),
sum(datediff(day, firstfundingdate,dateadd(day,m.number,'11/1/2005'))*fundedamount/sum(Fundedamount)
FROM #dqall d, Master.dbo.spt_Values m
Where dqstartdate <= dateadd(day,m.number,'11/1/2005')
and (dqenddate > dateadd(day,m.number,'11/1/2005') or dqendate is null)
and m.number >= 0
and m.number <= datediff(DAY,'11/1/2005','1/9/2006')
[/code]



Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page
   

- Advertisement -