おはようございます。
次のように、前のクエリの結果を使用して、多対多のテーブルにデータを入力しています...
WITH Temp AS
(
SELECT UserID, Result
FROM <Master_Table>
WHERE UserID IN (SELECT Name FROM Users)
)
INSERT INTO UserDecisions
(User_Id, Decision_Id)
VALUES
(
(SELECT Id FROM Users WHERE Temp.UserID = Users.Name),
(SELECT Id FROM Decisions WHERE Temp.Result = Decisions.Name)
)
実行すると、次のようなエラーが発生します。
Msg 4104, Level 16, State 1, Line 22
The multi-part identifier "Temp.UserID" could not be bound.
Msg 4104, Level 16, State 1, Line 23
The multi-part identifier "Temp.Result" could not be bound.
これをどのように解決しますか?Temp サブクエリは一時テーブルである必要がありますか?