gpt4 book ai didi

sql - concatrelated vba excel的使用

转载 作者:行者123 更新时间:2023-12-04 21:06:53 24 4
gpt4 key购买 nike

我在使用 sql 语句上的函数 concatrelated 时遇到问题。我想获得如下:

我的数据是:

A.CABNRO E01.EXCCEX
90001 500
87000 400
90001 450
90001 300
87000 500
76005

我想获得:
A.CABNRO NEW FIELD
90001 500,450,300
87000 400,500
76005

当我包含与 concatrelated 相关的语句时,以下代码不会运行。如果有人可以帮助我,我将不胜感激!!!
MYSQL = "SELECT A.CABFPR, A.CABCIA, A.CABCTR, B.CTRDTR, A.CABLOE, "
MYSQL = MYSQL & "A.CABNRO, A.CABCAR, A.CABFED, A.CABHOD, A.CABFEI, "
MYSQL = MYSQL & "A.CABHOI, A.CABFEF, A.CABHOF, A.CABFEE, A.CABHOE, "
MYSQL = MYSQL & "A.CABCCL, A.CABNEM, A.CABDEM "
MYSQL = MYSQL & "CONCATRELATED(EXCCEX, E01, A.CABNRO=E01.EXCNRO) "
MYSQL = MYSQL & "FROM BDYOBEL.AIPDTA.AIPCAB A "
MYSQL = MYSQL & "LEFT OUTER JOIN BDYOBEL.AIPDTA.AIPCTR B ON A.CABCIA=B.CTRCIA AND A.CABCTR=B.CTRCTR "
MYSQL = MYSQL & "LEFT OUTER JOIN BDYOBEL.AIPDTA.AIPEXC E01 ON A.CABNRO=E01.EXCNRO "
MYSQL = MYSQL & "WHERE A.CABCIA='LOR' AND A.CABFED>="
MYSQL = MYSQL & Chr$(39) & fini & Chr$(39) & "AND A.CABFED<=" & Chr$(39) & ffin & Chr$(39)
MYSQL = MYSQL & " AND (A.CABCTR='DM' OR A.CABCTR='L1' OR A.CABCTR='L5' OR A.CABCTR='LR') AND A.CABCAR<>'0'"

最佳答案

http://allenbrowne.com/func-concat.html说明

If the ConcatRelated function returns more than 255 characters, and you use it in a query as the source for another recordset, a bug in Access may return garbage for the remaining characters.



这可以解释为什么您的代码不起作用。
在 Access 中无法为不固定数量的列聚合数据。你能做的最好的事情就是写这样的东西,然后用文本编辑器把这些列组合起来。
TRANSFORM Sum(E01.EXCCEX) AS SumOfEXCCEX
SELECT A.CABNRO
FROM [BDYOBEL-AIPDTA-AIPCAB] AS A INNER JOIN [BDYOBEL-AIPDTA-AIPEXC] AS E01 ON
A.CABNRO = E01.EXCNRO
GROUP BY A.CABNRO
ORDER BY A.CABNRO DESC , E01.EXCCEX DESC
PIVOT E01.EXCCEX;

运行查询会为您的示例数据提供以下结果:
screenshot of access output .

关于sql - concatrelated vba excel的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12865752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com