将SQL转换为FetchXML错误?

时间:2017-03-27 08:56:21

标签: sql xml dynamics-crm crm fetchxml

尝试将以下内容转换为Fetch XML只是一个快速的尝试,但是下面有错误。

  

错误:解析SQL脚本时发生错误:不支持的语句类型:DECLARE

DECLARE 
    @OrganisationId uniqueidentifier

SELECT
    cil.mm_topprioritystatus,
    cil.mm_achievedcatalogproductName,
    cil.mm_achievedcatalogproductstatus,
    ci.mm_key
FROM
    mm_catalogitemtorganisationlinker cil
INNER JOIN
    mm_catalogitem ci on 
        ci.mm_catalogitemId = cil.mm_catalogitem    
where 
    mm_organisation = @OrganisationId
    and ci.mm_key in (
        'LEVEL1',
        'LEVEL2',
        'LEVEL3',
        'LEVEL4'
    )

请告知上面的fetchXML版本。

1 个答案:

答案 0 :(得分:2)

这是一种可能的解决方案:

<fetch>
  <entity name='mm_catalogitemtorganisationlinker' >
    <attribute name='mm_topprioritystatus' />
    <attribute name='mm_achievedcatalogproductName' />
    <attribute name='mm_achievedcatalogproductstatus' />
    <filter>
      <condition attribute='mm_organisation' operator='eq' value='{organizationid}' />
    </filter>
    <link-entity name='mm_catalogitem' from='mm_catalogitemid' to='mm_catalogitem' link-type='inner' alias='ci' >
      <attribute name='mm_key' />
      <filter>
        <condition attribute='mm_key' operator='in' >
          <value>LEVEL1</value>
          <value>LEVEL2</value>
          <value>LEVEL3</value>
          <value>LEVEL4</value>
        </condition>
      </filter>
    </link-entity>
  </entity>
</fetch>

当然,您必须按代码替换{organizationid}占位符。