SQL或VBA代码循环遍历两列数据 [英] SQL or VBA code to loop through two columns of data
问题描述
我有一个196000行的表(产品代码和相关的产品代码)。产品包含一对多链接产品代码,我希望在一行中显示。列是:
ProductCode LinkProduct
000507 000123
000507 000456
000507 000789
000508 123456
000508 654321
000508 879456
000508 123789
等等
我想将此数据更改为:
ProductCode LinkProducts
000507 000123,000456,000789
000508 123456,654321,879456,123789
等
我花了好几天尝试在Access中解决这个问题但是可以''做到了。有人请帮我完成这项任务。
如果您可以发布表的元数据(有关布局/结构的信息),这将更好用就像我在我的例子中使用的一样。单击回复按钮,您将可以访问我使用过的所有代码。 PK& FK代表Primary Key&外键分别为。请不要在格式化的布局中使用任何TAB,因为这将无法正确显示 - 仅用于布局的空间。
表名= [ tblStudent ]
展开 | 选择 | Wrap | 行号
字段名称数据类型
ProductCode文本
LinkProductCode文本
@limey
你仍然没有给我们muc h继续工作,所以我填写了一些缺少的空白:
- tblProductCodes包含Field [ProductCode],此字段是主键{TEXT}。
- tblLinkedProductCodes还包含[ProductCode]字段{TEXT},以及[LinkProductCode]字段。
- 基于[ProductCode] tblProductCodes和tblLinkedProductCodes之间存在1到MANY的关系]字段。
- 将以下公共功能复制并粘贴到标准代码模块:
展开 | / span> 选择 | 换行 | 行号
I have a table with 196000 rows (product code and related product codes). A product has one to many link product codes that I wish to display in one row. The columns are:
ProductCode LinkProduct
000507 000123
000507 000456
000507 000789
000508 123456
000508 654321
000508 879456
000508 123789
etc etc
I want to change this data to:
ProductCode LinkProducts
000507 000123,000456,000789
000508 123456,654321,879456,123789
etc
I''ve spent days trying to work this out in Access but can''t do it. Would somebody please help me with this task.解决方案This will work much better if you can post the meta-data (info about the layout / structure) of the table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I''ve used. PK & FK stand for Primary Key & Foreign Key respectively. Please don''t use any TABs in your formatted layout as this will not display correctly - Spaces only for layout.
Table Name=[tblStudent]
Expand|Select|Wrap|Line Numbers
Field Name Data Type
ProductCode Text
LinkProductCode Text
@limey
You still did not give us much to work on, so I filled in a few missing blanks:
- tblProductCodes contains the Field [ProductCode] and this Field is the Primary Key {TEXT}.
- tblLinkedProductCodes also contains the [ProductCode] Field {TEXT}, as well as a [LinkProductCode] Field.
- There is a 1 to MANY Relationship between tblProductCodes and tblLinkedProductCodes based on the [ProductCode] Field.
- Copy-and-Paste the following ''Public'' Function to a Standard Code Module:
Expand|Select|Wrap|Line Numbers
这篇关于SQL或VBA代码循环遍历两列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆