SQL Error 'Must declare the scalar variable "@Actions'

HI

Why am I getting this error when I have already declared it?

--Run the entire script in one go

DECLARE @Actions       TABLE  (ActionId uniqueidentifier)

--Grab actionid @Actions and insert into the variable table @Actions
INSERT INTO @Actions
SELECT actionid
FROM Action
Where Actionid in ('1F29300C-6059-4402-AB17-AB2D01674568', '5303D037-F50F-4E71-91F9-30BBC0993E68')

--Returns the 2 IDs as expected
Select *
from @Actions

--Now delete the 2 Ids from the @Actions Variable table
DELETE
FROM dbo.Action
WHERE ActionId  = @Actions

--I get error here when I go to delete the 2 Ids in the variable table

'Msg 137, Level 16, State 1, Line 3
Must declare the scalar variable "@Actions"..
wilko100Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
DELETE
FROM dbo.Action
WHERE ActionId   in (select ActionId from @Actions)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tim_csCommented:
It's because you are using @Actions in a where clause when it's a table.  You need to join to it in your delete statement instead of setting ActionID = @Actions.

DELETE Action
FROM
   dbo.Action a
   INNER JOIN @Action b
      ON a.actionid = b.actionID
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.