ルックアップクエリからクエリを更新する
-
05-07-2019 - |
質問
Access DBに変換するスプレッドシートがあります。入力した顧客名の列があり、これを会計システムの適切な顧客番号に置き換えます。
顧客情報と、ソースデータに挿入する必要があるIDを示すクエリを含むテーブルを作成しました。私が探しているのは:
UPDATE tblStarting_Data
SET CustomerID=x
WHERE TEMPCustomer=y
XおよびYはqryIDPerCustomerから取得されます。
ループを使用できますか?別のクエリを参照するにはどうすればよいですか
解決
MS Accessの別の可能性(Tomalakの回答から借用したオブジェクト名):
UPDATE tblStarting_Data, qryIDPerCustomer
SET tblStarting_Data.CustomerID=qryIDPerCustomer.CustomerID
WHERE tblStarting_Data.TEMPCustomer=qryIDPerCustomer.CustomerName
他のヒント
JOINが役立つと思います:
UPDATE
tblStarting_Data AS sd
INNER JOIN qryIDPerCustomer AS qc ON sd.TEMPCustomer = qc.CustomerName
SET
sd.CustomerID = qc.CustomerID;
これは、相関サブクエリとしても表現できます(ただし、結合構文が望ましい):
UPDATE
tblStarting_Data
SET
CustomerID = (
SELECT CustomerID
FROM qryIDPerCustomer
WHERE CustomerName = tblStarting_Data.TEMPCustomer
)
ループは必要ありません。両方のステートメントが tblStarting_Data
のすべてのレコードを1ステップで更新します。
所属していません StackOverflow