試圖插入到其他兩個表表一環SQL服務器:錯誤「必須聲明標量變量」
DECLARE @RowCount INT
SET @RowCount = (SELECT Max(FogTopicsID) FROM FSB_FogTopics)
DECLARE @I INT
SET @I = 1
WHILE (@I <= @RowCount)
BEGIN
DECLARE @FogID INT, @StudentID INT, @TopicID INT, @ProcessStudentId INT
SELECT @FogID = FogID, @StudentID = StudentID, @TopicID = TopicsID
FROM FSB_FogTopics
WHERE FogTopicsID = @I
SELECT @ProcessStudentId = ProStudentId
FROM FSB_ProcessStudents
WHERE ProcessId = @FogID AND StudentId = @StudentID
INSERT INTO FSB_ProcessTopics([ProcessStudentId], [TopicId])
VALUES (@ProcessStudentId, @TopicID)
SET @I = @I + 1
END
,但我得到一個錯誤
必須聲明標量變量
@ProcessStudentId
您確定設置了該值嗎? – Forklift
你爲什麼首先用循環做這件事?這似乎是一個壞主意.. – Siyual