Davidmc555
Programmer
Hi, I'm trying to write a stored procedure that updates our floor database. I want it to then check that the quantities produced and scanned match and to list the individual items as gone as it does so.
This portion is only for the query, I'll finish the Stored procedure later once this bit is correct. I get a run error of "Server: Msg 107, Level 16, State 2, Line 1
The column prefix 'T1' does not match with a table name or alias name used in the query." which is the bit in the if statement. I tried juggling the code and looking at other posts but couldn't find an answer.
Anybody got any suggestions? I'd be most grateful.
Code:
Declare @TotalMade integer
Declare @TotScanned integer
Update CamdenAccess
Set QuantityScanned = QuantityScanned + T1.SumQty, BarcodesScanned = BarcodesScanned + T1.CountQty,
@TotScanned = (SELECT BarCodesScanned FROM CamdenAccess Where AccessID = T1.AccessID),
@TotalMade = (SELECT BarCodesCreated FROM CamdenAccess WHERE AccessID = T1.AccessID)
From
CamdenAccess Inner Join
(
SELECT
AccessoryPackItems.AccessID, SUM(AccessoryPackItems.Quantity) AS SumQty, COUNT(AccessoryPackItems.Quantity) As CountQty
FROM CamdenAccess
INNER JOIN
AccessoryPackItems ON
CamdenAccess.AccessID = AccessoryPackItems.AccessID
--WHERE (AccessoryPackItems.PackageID = @PackID)
WHERE (AccessoryPackItems.PackageID = '44')
GROUP BY AccessoryPackItems.AccessID
) T1
On
CamdenAccess.AccessID = T1.AccessID
if @TotScanned = @TotalMade --all items for that line on the order have been completely delivered
BEGIN
UPDATE CamdenAccess SET Gone = 1 WHERE AccessID = T1.AccessID
END
This portion is only for the query, I'll finish the Stored procedure later once this bit is correct. I get a run error of "Server: Msg 107, Level 16, State 2, Line 1
The column prefix 'T1' does not match with a table name or alias name used in the query." which is the bit in the if statement. I tried juggling the code and looking at other posts but couldn't find an answer.
Anybody got any suggestions? I'd be most grateful.