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)
 function X select

Author  Topic 

netcamnic
Starting Member

9 Posts

Posted - 2006-02-16 : 08:31:39
I am doing a select and doing a sum in a function .. and of this mistake??
someone can help me
select a.dtvcto_doccr as data,
b.dt_vcto_doccp as data1,
Sum(isnull(dbo.F_CALCULA_SALDO(Max(a.id_doccr),getdate(),isnull(dbo.F_CALCULA_JUROS(Max(a.id_doccr),getdate()), 0),isnull(dbo.F_CALCULA_MULTA(Max(a.id_doccr),getdate()), 0)), 0)) as Saldo,

Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

regards,
Marcos

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-16 : 08:41:38
As error indicates sum(max(col)) is not allowed

Post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

netcamnic
Starting Member

9 Posts

Posted - 2006-02-16 : 09:02:37
Thanks,
the results is perfect now
Marcos
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-16 : 09:10:05
Post your changed query

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

netcamnic
Starting Member

9 Posts

Posted - 2006-02-16 : 09:42:28
select a.dtvcto_doccr as data,
b.dt_vcto_doccp as data1,--a.id_doccr,b.id_doccp,

Sum(isnull(dbo.F_CALCULA_SALDO(a.id_doccr,getdate(),isnull(dbo.F_CALCULA_JUROS(a.id_doccr,getdate()), 0),isnull(dbo.F_CALCULA_MULTA(a.id_doccr,getdate()), 0)), 0)) as Saldo,
isnull(sum(b.saldo_doccp),0) as saldo_doccp
from doccr a
full join
doccp b
on a.dtvcto_doccr = b.dt_vcto_doccp
--where a.dtvcto_doccr between @DT_INICIAL-1 and @DT_FINAL+1
--or b.dt_vcto_doccp between @DT_INICIAL-1 and @DT_FINAL+1
group by a.dtvcto_doccr,b.dt_vcto_doccp
order by a.dtvcto_doccr,b.dt_vcto_doccp
Go to Top of Page
   

- Advertisement -