3

我正在处理我的第一个 Access 2010 数据库,并且在编辑从查询返回的记录集时遇到了问题。

我有两张表,“drugs”和“warehouse_stock”。在“药物”中,我有药物的名称。在另一张表中,我有相应的信息。对于那些在“药品”表中的药品,药剂师将管理它们的数量和其他相对值,例如每种药品的输入数量和特定的有效期。药剂师可以将相同的药物信息导入“warehouse_stock”,但有效期不同。

“warehouse_stock”中的每一行数据都以active_substance/strength/strength_type/dosage_form为特征。这四个值在“药物”中的一行数据中必须相同。药剂师将能够更新现有行数据的 curr_date、in_quant、out_quant_expiry_date 和品牌(来自“warehouse_stock”)并导入“drugs”中存在的新数量的药物。

我现在的查询是:

SELECT warehouse.active_subs,
   warehouse.strength,
   warehouse.strength_type,
   warehouse.dosage_form,
   warehouse.curr_date,
   warehouse.in_quant,
   warehouse.out_quant,
   warehouse.expiry_date,
   warehouse.available_stock,
   warehouse.brand,
   warehouse.ID
FROM   drugs
       RIGHT JOIN warehouse
         ON ( drugs.active_substance = warehouse.active_subs )
            AND ( drugs.strength = warehouse.strength )
            AND ( drugs.strength_type = warehouse.strength_type )
            AND ( drugs.dosage_form = warehouse.dosage_form )
WHERE  ( ( ( warehouse.active_subs ) LIKE
"*" &
Forms!Pharmacy.form!pharmacy_warehouse_stock_Subform.form!warehouse_stock_act_sub & "*" )
AND ( ( warehouse.strength ) LIKE
"*" &
Forms!Pharmacy.form!pharmacy_warehouse_stock_Subform.form!warehouse_stock_strength & "*" )
AND ( ( warehouse.strength_type ) LIKE
"*" &
Forms!Pharmacy.form!pharmacy_warehouse_stock_Subform.form!warehouse_stock_strength_type & "*" )
AND ( ( warehouse.dosage_form ) LIKE
"*" &
Forms!Pharmacy.form!pharmacy_warehouse_stock_Subform.form!warehouse_stock_dosage_form & "*" ) );

有没有办法使结果可更新?

在此先感谢您的任何建议!

齐诺纳斯

4

3 回答 3

0

为了使该表可更新,您需要删除未在 From 或 Where 子句中使用的连接(直到现在)。但是,您提到您试图warehouse仅过滤具有drugs值的结果。为此,您应该使用 Exists 函数,它允许您传递相关子查询(因为内部查询中的项目与外部查询中的项目匹配)。

Select W.active_subs, W.strength, W.strength_type, W.dosage_form
    , W.curr_date, W.in_quant, W.out_quant, W.expiry_date
    , W.available_stock, W.brand, W.ID
From warehouse As W
Where  ( ( ( W.active_subs ) LIKE
"*" &
Forms!Pharmacy.form!pharmacy_warehouse_stock_Subform.form!warehouse_stock_act_sub & "*" )
AND ( ( W.strength ) LIKE
"*" &
Forms!Pharmacy.form!pharmacy_warehouse_stock_Subform.form!warehouse_stock_strength & "*" )
AND ( ( W.strength_type ) LIKE
"*" &
Forms!Pharmacy.form!pharmacy_warehouse_stock_Subform.form!warehouse_stock_strength_type & "*" )
AND ( ( W.dosage_form ) LIKE
"*" &
Forms!Pharmacy.form!pharmacy_warehouse_stock_Subform.form!warehouse_stock_dosage_form & "*" ) )
    And Exists  (
                Select 1
                From drugs As D1
                Where D1.active_substance = W.active_subs
                    And D1.strength = W.strength
                    And D1.strength_type = W.strength_type
                    And D1.dosage_form = W.dosage_form
                )
于 2012-05-16T15:29:19.683 回答
0

尝试:

<...>
warehouse.ID
FROM  warehouse 
LEFT JOIN Drugs
     ON ( drugs.active_substance = warehouse.active_subs )
        AND ( drugs.strength = warehouse.strength )
        AND ( drugs.strength_type = warehouse.strength_type )
        AND ( drugs.dosage_form = warehouse.dosage_form )
于 2012-05-15T11:24:21.243 回答
0

您的要求完全不明确,标题与您对问题的文字描述以及提供的查询有很大不同,甚至不同。

如果像 active_subs、strength、strength_type、dose_form 这样的字段在两个表中应该具有相同的值,那么你的设计可能有缺陷。您应该从其中一张桌子上摆脱它们。为什么不将这些字段放在一个表中并通过 id 连接它们?

编辑:经过无休止的讨论,这就是我的理解。存在很大的沟通差距,所以我确信 OP 对此并不满意 :)

SELECT warehouse.ID, drugs.quantity, warehouse.active_subs, warehouse.strength, 
       warehouse.strength_type, warehouse.dosage_form, warehouse.curr_date, 
       warehouse.in_quant, warehouse.out_quant, warehouse.expiry_date, 
       warehouse.available_stock, warehouse.brand --whatever values you want
FROM   warehouse
JOIN   drugs ON drugs.active_substance = warehouse.active_subs AND 
                drugs.strength = warehouse.strength AND 
                drugs.strength_type = warehouse.strength_type AND
                drugs.dosage_form = warehouse.dosage_form
WHERE  (....); --if ever there is one
UPDATE warehouse_stock SET curr_date=@curr_date, in_quant=@in_quant, 
                           out_quant=@out_quant, expiry_date=@expiry_date, 
                           brand=@brand;

我不清楚 OP 想要更新什么价值观。在更新查询中使用合适的 where 子句。

于 2012-05-15T20:33:19.157 回答