【问题标题】:How can I get data from joined tables using fetchxml如何使用 fetchxml 从连接表中获取数据
【发布时间】:2021-04-02 00:05:48
【问题描述】:

我有两张表 Tasks 和 Notes

Tasks

|身份证 |任务 | |----|--------| | 1 |任务1| | 2 |任务2| | 3 |任务3|

Notes

|身份证 |任务 ID |正文 | |----|--------|------| | 1 | 1 |文本1| | 2 | 1 |文本2| | 3 | 1 |文本3| | 4 | 2 |文本4| | 5 | 2 |文本5| | 6 | 3 |正文6|

我希望 fetchxml 的结果是:

[ {Id: 1, Task: "task1", Notes: ["text1", "text2", "text3"]},{Id: 2, Task: "task2", Notes: ["text4", "text5"]},{Id: 3, Task: "task3", Notes: ["text6"]}]

我知道如何使用 SQL 来做这件事,但很难找到任何帮助来使用 fetchxml 谁能帮帮我?

【问题讨论】:

  • 其实fetchxml跟Dynamics CRM有关,你的意思是那个查询——对吗?

标签: sql fetchxml


【解决方案1】:
SELECT n.TaskId as Id,t.Task,
group_concat(n.Text) end AS Notes
FROM tasks t,notes n
On t.Id=n.TaskId
WHERE 
group by n.TaskId,t.Task

我在下面写fetchxml

 Select
     n.TaskId as [@id],
     t.Task as [@Task],
    
    (
    Select
     group_concat(n.Text) as [@Notes],
    
    FROM tasks t,notes n
    On t.Id=n.TaskId
    WHERE 
    group by n.TaskId,t.Task
    FOR XML Raw('notes'),TYPE
    )
    
    FROM tasks t
    WHERE 
    group by t.Id,t.Task
    
    FOR XML PATH('tasks'),
    ROOT('myFetchXml')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    • 2021-04-01
    • 1970-01-01
    相关资源
    最近更新 更多