带有customSQL的DataSource

时间:2014-02-24 14:39:14

标签: sql-server smartclient

我想使用SQL查询在3个表之间进行连接,你能纠正我的语法还是给我正确的语法?我的应用程序即使出现这个错误也无法启动! 我提前谢谢你 这是我的代码:

<DataSource 
      dbName="SQLServer_CRM"
      dataSourceVersion="1"
      generatedBy="v8.3p"
      serverType="sql"
>

             <fields>
                <field name="OBJ_ID" type="int" title="OBJ ID" customSQL="true">
                    <nativeName>crm_obj_idnum</nativeName>
                    <tableName>crm_objects</tableName>
                       </field>

            </fields> 

           <operationBindings operationType="fetch">
                <customSQL>

        SELECT  OBJ_DET.[crm_obj_idnum]         AS OBJ_ID
        ,OBJ_DET.[crm_obj_kind]                         AS OBJ_KIND
        ,OBJ_KN.[crm_kind_name]             AS OBJ_KIND_NAME      
        ,OBJ_FATHER.crm_obj_name            AS FATHER_NAME
        ,OBJ_DET.[crm_obj_parent_idnum]         AS FATHER_ID
        ,OBJ_DET.[crm_obj_name]                         AS OBJ_NAME
        ,OBJ_DET.[crm_obj_desc]                         AS OBJ_DESC
        ,OBJ_DET.[crm_obj_isactive]         AS OBJ_ACTIVE
        fROM 
            [foveaprocess_easycrm].[dbo].[crm_objects]            OBJ_DET,
            [foveaprocess_easycrm].[dbo].[crm_objects]            OBJ_FATHER,
            [foveaprocess_easycrm].[dbo].[crm_kind]               OBJ_KN
        WHERE 
        OBJ_DET.crm_obj_parent_idnum=OBJ_FATHER.crm_obj_idnum
        AND OBJ_DET.crm_obj_kind = OBJ_KN.crm_kind_idnum
        UNION ALL
        SELECT 
          [crm_attrdat_fk_obj_idnum]                   AS OBJ_ID
          ,OBJ_FATHER_DATA.crm_obj_kind                AS OBJ_KIND
          ,OBJ_KN.[crm_kind_name]                      AS OBJ_KIND_NAME
          ,OBJ_FATHER_DATA.crm_obj_name                AS FATHER_NAME
          ,[crm_attrdat_fk_obj_idnum]                  AS FATHER_ID
   ,case OBJ_ATTR_DATA.crm_attr_datatype WHEN 'A' THEN [crm_attrdat_data_A1] END AS OBJ_NAME
      ,OBJ_ATTR_DATA.crm_attr_name                 AS OBJ_DESC
      ,[crm_attrdat_isactive]                      AS OBJ_ACTIVE
     FROM 
            [foveaprocess_easycrm].[dbo].[crm_attrdata]           OBJ_DATA,
            [foveaprocess_easycrm].[dbo].[crm_attributs]          OBJ_ATTR_DATA,
            [foveaprocess_easycrm].[dbo].[crm_objects]            OBJ_FATHER_DATA,
            [foveaprocess_easycrm].[dbo].[crm_kind]           OBJ_KN

     WHERE 
           OBJ_DATA.crm_attrdat_fk_attr_idnum=OBJ_ATTR_DATA.crm_attr_idnum
           AND OBJ_DATA.crm_attrdat_fk_obj_idnum=OBJ_FATHER_DATA.crm_obj_idnum
           AND OBJ_ATTR_DATA.crm_attr_fk_kind_idnum = OBJ_KN.crm_kind_idnum          

                </customSQL>
            </operationBindings>   
        </DataSource>

2 个答案:

答案 0 :(得分:0)

单引号在XML中无效。尝试更改此行

,case OBJ_ATTR_DATA.crm_attr_datatype WHEN 'A' THEN [crm_attrdat_data_A1] END AS OBJ_NAME

,case OBJ_ATTR_DATA.crm_attr_datatype WHEN &apos;A&apos; THEN [crm_attrdat_data_A1] END AS OBJ_NAME

答案 1 :(得分:0)

问题解决了! 我必须更改DataSource的文件名,该文件名应与数据库中的表或视图相同