I have this table variable declaration followed by a query:
DECLARE @CurrentItems TABLE
(
ItemId uniqueidentifier,
ItemUnits int
)
UPDATE U SET U.Units = U.Units + [@CurrentItems].ItemUnits
FROM @CurrentItems CI INNER JOIN U ON U.UId=CI.ItemId;
And U
is defined as follows:
CREATE TABLE [dbo].[U] (
[UId] UNIQUEIDENTIFIER UNIQUE NOT NULL,
[Units] INT DEFAULT ((0)) NOT NULL
);
When I run that in SQL Management Studio against SQL Server 2005 Express I get the following:
Msg 208, Level 16, State 1, Line 24
Invalid object name '@CurrentItems'.
I've already looked through this and this very similar questions but can't figure out how to solve the problem.
What's the actual problem and how do I resolve that?
UPDATE U SET U.Units = U.Units + CI.ItemUnits FROM @CurrentItems CI INNER JOIN U ON U.UId=CI.ItemId;
works, I have tried right now – Coated