如何根据msaccess(sql)中表单的Map表和值生成id序列?

tsm1rwdh  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(276)

我想根据ms access中的表单值生成id。然后,对于生成的每个id,根据Map表在末尾添加另外4个数字,创建一组id,表示不同时间点的不同八位字节(基于初始id和Map表的12个id)。
例如,如果基于表单值生成的id是123456,我想再添加四个数字并创建一组id,比如从Map表中。比如,

123456**1111**
123456**1112**
123456**1113**

等等。
到目前为止,我在每个主id的末尾加上四个数字,生成一组12个id。
我是access的初学者,我尝试过一些代码:

UPDATE Table1 SET GenID = UPDATE Table1 SET Table1.GenID = t1 (SELECT Map.V FROM MAP as t1)

但是,我得到一个错误,access没有将map识别为有效的字段或表达式。我能把这个问题分解成这个问题。但无法找到进一步的方法并设计查询。
示例数据:(short\u id和long\u id表使用它们下面的Map表,如图所示。)
短id表:

----------------------------------------------------
    ID | Subject_ID | Organ_Type | Category | Short_ID
    -----------------------------------------------------
    1  | 100        | Kidney     |    A     | 100200300
    -----------------------------------------------------
    2  | 400        | Heart      |    B     | 400500600

短id的Map表:
表1的map1:

---------------------
Map_from  |  Map_to |
---------------------
Kidney    | 200     |
Heart     | 500     |
---------------------

表1的map2:

-----------------------------
    Map_cat_from  |  Map_cat_to |
    -----------------------------
    A              | 300        |
    B              | 600        |
    -----------------------------

长id表:(这里显示的只是2个时间点的示例,而不是12个时间点)

---------------------------------------------------
Subject_ID | Short_ID   | Long_ID  Timepoint       |
---------------------------------------------------
100        | 100200300  |  1002003000001           |
---------------------------------------------------
100        | 100200300  |  1002003000002           |
---------------------------------------------------
400        | 400500600  |  4005006000001           |
---------------------------------------------------
400        | 400500600  |  4005006000002

长id表的时间点Map:

------------------------------
Timepoint | Value_to_append  |
------------------------------
 1        | 0001             |
------------------------------
 2        | 0002             |

当表单中给出输入时,我需要直接从Map表生成这些短id和长id(类别、器官类型、受试者id)
太长,读不下去了
从Map表和表单值生成id(id创建)
在末尾添加四个数字,并基于Map表(在末尾添加12个四位数)创建一组12个id(长id创建)

2lpgd968

2lpgd9681#

首先,创建一个查询qshortid:

SELECT 
    Table1.ID,  
    Table1.Subject_ID, 
    Table1.Organ_Type, 
    Table1.Category, 
    [Subject_ID] & [Map_to] & [Map_cat_to] AS Short_ID
FROM 
    (Table1 
INNER JOIN 
    Map1 
    ON Table1.Organ_Type = Map1.Map_from) 
INNER JOIN 
    Map2 
    ON Table1.Category = Map2.Map_cat_from;

输出:

接下来,创建一个查询,它将返回12行:

SELECT DISTINCT 
    Abs([id] Mod 12) AS N
FROM 
    MSysObjects;

最后,创建一个笛卡尔(乘法)查询qlongid:

SELECT Table1.ID, Table1.Subject_ID, Table1.Organ_Type, Table1.Category, [Subject_ID] & [Map_to] & [Map_cat_to] AS Short_ID
FROM (Table1 INNER JOIN Map1 ON Table1.Organ_Type = Map1.Map_from) INNER JOIN Map2 ON Table1.Category = Map2.Map_cat_from;
SELECT 
    QShortID.Subject_ID, 
    QShortID.Short_ID, 
    [Short_ID] & Format([N] + 1, "0000") AS Long_ID
FROM 
    QShortID, 
    Dozen
ORDER BY 
    [Short_ID] & Format([N] + 1, "0000");

输出:

编辑:
要使用时间点Map,请使用:

SELECT 
    QShortID.Subject_ID, 
    QShortID.Short_ID, 
    [Short_ID] & [Value_to_append] AS Long_ID
FROM 
    QShortID, 
    TimepointMap
ORDER BY 
    [Short_ID] & [Value_to_append];

输出:

相关问题