|
|
Question : Group By clause without an aggregate function
|
|
I have not seen this syntax before for a Group By clause
select cdtiss.AssetControlIssuerId, cdtiss.EntryDate, cdtiss.Region, cdtiss.IssuerId, cdtiss.Displayname INTO #tempCDTIssuers from ( select AssetControlIssuerId, cdti.EntryDate, min(HierarchyPosition) as HierarchyPosition, cdti.DisplayName from RFCommon..CDTIssuer cdti JOIN Issuer i on i.IssuerId = cdti.IssuerId WHERE cdti.EntryDate = @RunDate group by AssetControlIssuerId, cdti.EntryDate ) p JOIN RFCommon..CDTIssuer cdtiss on cdtiss.AssetControlIssuerId = p.AssetControlIssuerId AND cdtiss.EntryDate = p.EntryDate AND cdtiss.HierarchyPosition = p.HierarchyPosition group by cdtiss.AssetControlIssuerId, cdtiss.EntryDate, cdtiss.Region, cdtiss.IssuerId
Will this return a consistent set of results with a Distinct Displayname field value?
|
Answer : Group By clause without an aggregate function
|
|
Unfortunately, your answer to them has to be that the logic is, at best inconsistent and at worst fatally flawed.
You are quite right that there will be all kinds of bogus things happening around the DisplayName determination. There is also no "simple fix" since no one seems to know what it was supposed to do anyway.
I would ask them to start with a clean sheet of paper and describe the report they really want. Then you can go off an pretend to evaluate how well the existing code matches the requirement. Take, oh say 5 minutes to do that then propose to write a new report that actually meets their needs.
Best of luck, Bill
|
|
|
|
|