我正在处理我的第一个Access 2010数据库,并且在编辑查询返回的记录集时遇到了问题。
我有两张桌子,“药物”和“warehouse_stock”。在“毒品”中,我有药物的名称。在另一张表中,我有相应的信息。对于那些在“药物”表中的药物,药剂师将管理它们的数量和其他相对值,例如具有特定有效期的每种药物的输入量。药剂师可以将“warehouse_stocK”导入药物的相同信息但具有不同的有效期。
“warehouse_stock”中的每一行数据由active_substance / strength / strength_type / dosage_form表征。这四个值在“药物”的行数据中必须相同。药剂师将能够更新现有行数据的curr_date,in_quant,out_quant_expiry_date和品牌(来自“warehouse_stock”),并导入“药物”中存在的新数量的药物。
我现在的查询是:
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 & "*" ) );
有没有办法让结果更新?
提前感谢任何建议!
Zinonas
答案 0 :(得分: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 )
答案 1 :(得分:0)
您的要求一点都不清楚,标题与您对问题的文字描述以及提供的查询有很大不同,甚至不同。
如果像active_subs,strength,strength_type,dosage_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子句。
答案 2 :(得分:0)
为了使此表可更新,您需要删除From和Where子句中未使用的连接(直到现在)。但是,您提到您尝试仅针对warehouse
值的drugs
结果过滤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
)
个结果。为此,您应该使用Exists函数,该函数允许您传递相关子查询(内部查询中的项目与外部查询中的项目匹配)。
{{1}}