我有以下SQL查詢:插入使用變量
Declare @Total_SysDown as int,
@Login_SysDown as int
Set @Total_SysDown = (SELECT SCHED_SYS_DOWN FROM AGT_SC AS S)
Set @Login_SysDown = (SELECT SYS_DOWN FROM AGT_AC AS A)
Insert Into dbo.DATA(DATE,ID,LNAME,FNAME,Total_SysDown,Login_SysDown)
Select C.DATE,C.ID,E.Last_Name,E.First_Name,@Total_SysDown @Login_SysDown
From dbo.AGT as C Inner Join dbo.EMP as E ON C.ID = E.ID
Group by C.ID,C.DATE,E.Last_Name,E.First_Name
這或只是與SELECT語句中的變量給我的子查詢返回錯誤大於1倍的值。據我所知,這意味着我應該一次插入一條記錄,但我不確定如何做到這一點。有沒有我應該投入的一段時間陳述,還是我的變數實際上首先妨礙了我?
AGT_SC和AGT_AC的值與AGT或EMP有什麼關係?有沒有ID –