This is the code:
Select BCPP.*
from ViewPBCPP BCPP
inner join
(
Select MBC.PC PC
,MRT.Name CT
,Max(dbo.CalcDatefromUTC(MBC.CreatedDate)) as LRDate
from TableBACC MBC
inner join TableSC.RT MRT
ON MBC.RTid = MRT.id
where MBC.Isdeleted = 'False'
and MBC.PC <> 'NULL'
Group by MBC.PC
,MRT.Name
) MBCR
ON BCPP.P_id = MBCR.PC
and BCPP.CreatedDate = MBCR.LRDate
and BCPP.CT = MBCR.CT
Now Max(dbo.CalcDatefromUTC(MBC.CreatedDate)) is actually a function
Query above works fine with Max(dbo.CalcDatefromUTC(MBC.CreatedDate))
Now when I write
Max(dbo.CalcDatefromUTC(MBC.CreatedDate)) + Min(dbo.CalcDatefromUTC(MBC.CreatedDate))
I cannot extract any values at all from this query written above
If I write just
(dbo.CalcDatefromUTC(MBC.CreatedDate))
it gives me error that it does not contained aggregate function or the group by function
I actually want this
(dbo.CalcDatefromUTC(MBC.CreatedDate))
so that I can use all the values of this function rather than just MAX values of it
How can I change this code written above to achieve my objective??
Anyone??
You can’t have
dbo.CalcDatefromUTC(MBC.CreatedDate)in theSELECTlist as neither you can haveMBC.CreatedDatebecause it’s not in theGROUP BYlist.You can have
MAX(MBC.CreatedDate)though because it uses an aggregate function (MAX) on thta column. You can also have:which is the same actually (although maybe a bit faster), as:
From your comments, I assume the above is not very helpful. Perhaps grouping by
MBC.CreatedDateas well is what you want: