Access: transform rows to columns with many different row-values

こ雲淡風輕ζ 提交于 2019-12-13 09:52:19

问题


Let me start to say that I know that transforming rows to columns can be done with the TRANSFORM command. Actually, I've learned that on this great site, reason enough for me to register :)

The problem I have is that I would like to transform rows into columns without every different value in the row is going to be a unique column. I'll try to explain it by an example of my Access table, see the picture in the link:

This query shows products (first column loar_aid), with pieces of text to describe the product. Every product has one value tekst1, tekst2 and tekst3. But column tregel1 can contain up to 3 different pieces of text for 1 product. I would like to transform this tregel1 to 3 columns: tregel1_firstValue, tregel1_secondValue, tregel1_thirdValue, if you know what I mean.

Eventually I would like to make labels with this table as a source (every column a rule on the label). Therefore the values should ideally be next to each other.

Could someone help me with this problem? Help will be greatly appreciated!


回答1:


You need a record sequence ID for each unique group. The following relies on an autonumber ID field to provide a unique identifier for each record in the original table to define sort order in DCount() expression.

TRANSFORM First(Table3.tregel1) AS FirstOftregel1
SELECT Table3.loar_aid, Table3.tekst2, Table3.tekst3
FROM Table3
GROUP BY Table3.loar_aid, Table3.tekst2, Table3.tekst3
PIVOT DCount("*","Table3","loar_aid='" & [loar_aid] & "' AND tekst1='" & [tekst1] & "' AND tekst2='" & [tekst2] & "' AND Nz(tekst3,'None')='" & Nz([tekst3],"None") & "' AND ID<" & [ID])+1;

Be aware this type of query using DCount() or a nested subquery can perform slowly on very large dataset.



来源:https://stackoverflow.com/questions/49274815/access-transform-rows-to-columns-with-many-different-row-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!