Skip to content

[BUG] null reference with a CTE #706

Description

@sybaris

Describe the bug
Object reference not set to an instance of an object

To Reproduce
Query to reproduce the behavior:

    WITH ComponentInSeveralSolutions AS (
        SELECT SC.objectid,componenttypename,componenttype, STRING_AGG(S.uniquename, ';') AS SolutionName
        FROM solutioncomponent SC
        LEFT OUTER JOIN solution S ON SC.solutionid = S.solutionid
        WHERE 1=0
        GROUP BY SC.objectid,componenttypename,componenttype
        HAVING COUNT(*)>1)

    SELECT *,
     CASE
            WHEN ComponentType = 9 THEN (SELECT W.displayname FROM metadata.globaloptionset W WHERE W.metadataid = objectid)
            ELSE NULL
        END AS ComponentName
    FROM ComponentInSeveralSolutions
    order by Componenttype, ComponentName    

Expected behavior
The correct result

Screenshots

Image

Environment (please complete the following information):

  • SQL 4 CDS edition: XrmToolBox
  • Results of SELECT @@VERSION: Microsoft Dataverse - 9.2.25082.179
    SQL 4 CDS - 10.1.0.0
    sept. 02 2025 11:14:15
    Copyright © 2020 - 2025 Mark Carrington

Additional context
Notice that with version 9.6.1 of the engine, I do not have the issue.

Sponsorship
If you find this tool useful, please consider sponsoring its development.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions