Describe the bug
Adding a count() to either the select or having clause of a GROUP BY performed against a sub-selected query generates:
Msg 0, Level 20, State 1, Line 8
Object reference not set to an instance of an object.
To Reproduce
Query to reproduce the behavior:
I can execute this query without the having count(*) > 1 clause, but it fails with the error above when I add that clause. I've also tried count(distinct t.owk_workrequesttype) but get the same error.
select t.owk_wrno
from
(
select distinct owk_wrno,owk_workrequesttype
from owk_workrequest wr
where owk_wrno is not null
) t
group by t.owk_wrno
having count(*) > 1
;
Same error occurs using this query:
select t.owk_wrno,count(distinct t.owk_workrequesttype) as [count]
from
(
select distinct owk_wrno,owk_workrequesttype
from owk_workrequest wr
where owk_wrno is not null
) t
group by t.owk_wrno
Expected behavior
Query should list owk_wrno values that have more than one owk_workrequesttype in the owk_workrequest table.
Screenshots
Environment (please complete the following information):
- SQL 4 CDS edition: XrmToolbox
- Results of
SELECT @@VERSION:
Microsoft Dataverse - 9.2.25061.154
SQL 4 CDS - 9.6.1.0
May 02 2025 14:00:23
Copyright © 2020 - 2025 Mark Carrington
Additional context
n/a
Sponsorship
If you find this tool useful, please consider sponsoring its development.
Describe the bug
Adding a count() to either the select or having clause of a GROUP BY performed against a sub-selected query generates:
Msg 0, Level 20, State 1, Line 8
Object reference not set to an instance of an object.
To Reproduce
Query to reproduce the behavior:
I can execute this query without the
having count(*) > 1clause, but it fails with the error above when I add that clause. I've also tried count(distinct t.owk_workrequesttype) but get the same error.Same error occurs using this query:
Expected behavior
Query should list owk_wrno values that have more than one owk_workrequesttype in the owk_workrequest table.
Screenshots
Environment (please complete the following information):
SELECT @@VERSION:Microsoft Dataverse - 9.2.25061.154
SQL 4 CDS - 9.6.1.0
May 02 2025 14:00:23
Copyright © 2020 - 2025 Mark Carrington
Additional context
n/a
Sponsorship
If you find this tool useful, please consider sponsoring its development.