Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JOIN with 2 conditions no longer works 9.1.0 #486

Closed
janis-veinbergs opened this issue Jun 13, 2024 · 4 comments
Closed

JOIN with 2 conditions no longer works 9.1.0 #486

janis-veinbergs opened this issue Jun 13, 2024 · 4 comments

Comments

@janis-veinbergs
Copy link

janis-veinbergs commented Jun 13, 2024

So as I was writing my query and got it working... I updated XTB SQL4CDS to 9.1.0 and suddenly cannot run the query and am greeted with error:

Msg 10337, Level 16, State 1, Line 1
'prefix_servicecontract' entity doesn't contain attribute with Name = 'conn.record2id' and NameMapping = 'Logical'. MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False, Timestamp=937808190, MinActiveRowVersion=937808190, MetadataInstanceId=27404280

Query that worked and now errors out:

SELECT 1    
FROM dbo.account a
INNER JOIN dbo.prefix_servicecontract sc ON sc.prefix_accountid = a.accountid
INNER JOIN dbo.contact authp ON authp.accountid = a.accountid
INNER JOIN dbo.connection conn ON conn.record1id = authp.contactid AND conn.record2id = sc.prefix_servicecontractid
  • If I remove two constraints within conn join and leave only 1 then it works.
  • Moving conn.record2id = sc.prefix_servicecontractid to WHERE clause spits same error

I may have had 9.0.1 before or maybe earlyer.

This refactor works:

SELECT 1
FROM dbo.connection conn
INNER JOIN dbo.prefix_servicecontract sc ON sc.prefix_servicecontractid = conn.record2id
INNER JOIN dbo.contact authp ON authp.contactid = conn.record1id
INNER JOIN dbo.account a ON authp.accountid = a.accountid

But if I add WHERE sc.prefix_accountid = a.accountid to be more correct, I get:

'prefix_servicecontract' entity doesn't contain attribute with Name = 'a.accountid' and NameMapping = 'Logical'. MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False, Timestamp=937808190, MinActiveRowVersion=937808190, MetadataInstanceId=27404280
@MarkMpn
Copy link
Owner

MarkMpn commented Jun 14, 2024

Thanks for the details. I can't reproduce this error at the moment, but it looks like the server is having problems evaluating the cross-table column comparison condition.

Could you please post the FetchXML that this query generates, along with the results of SELECT @@VERSION?

@janis-veinbergs
Copy link
Author

janis-veinbergs commented Jun 14, 2024 via email

@MarkMpn
Copy link
Owner

MarkMpn commented Jun 15, 2024

That is almost certainly the issue - if you can get me the version number details I can build in an extra check so it doesn't attempt to use this feature in the on-prem version.

@chironh
Copy link

chironh commented Jun 18, 2024

Experiencing a similar issue (online):

select account.accountid
from account
inner join inf_place ON account.inf_placevisitaddressid = inf_place.inf_placeid
inner join inf_stateprovincecountydepartement ON inf_place.inf_stateprovincecountydepartementid = inf_stateprovincecountydepartement.inf_stateprovincecountydepartementid
where account.address1_stateorprovince is null or account.address1_stateorprovince != inf_stateprovincecountydepartement.inf_name

image

Giving me fetchxml:

<fetch xmlns:generator='MarkMpn.SQL4CDS'>
  <entity name='account'>
    <attribute name='accountid' />
    <link-entity name='inf_place' to='inf_placevisitaddressid' from='inf_placeid' alias='inf_place' link-type='inner'>
      <link-entity name='inf_stateprovincecountydepartement' to='inf_stateprovincecountydepartementid' from='inf_stateprovincecountydepartementid' alias='inf_stateprovincecountydepartement' link-type='inner' />
    </link-entity>
    <filter type='or'>
      <condition attribute='address1_stateorprovince' operator='null' />
      <filter>
        <condition valueof='inf_stateprovincecountydepartement.inf_name' attribute='address1_stateorprovince' operator='ne' />
        <condition attribute='address1_stateorprovince' operator='not-null' />
        <condition attribute='inf_name' operator='not-null' />
      </filter>
    </filter>
  </entity>
</fetch>

Last condition breaks the query.

Creating a calculated condition fixes the issue:

or account.address1_stateorprovince != inf_stateprovincecountydepartement.inf_name + ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants