Sql server 删除ID在#中的行
为什么我不能这样做:Sql server 删除ID在#中的行,sql-server,sql-server-2008,tsql,Sql Server,Sql Server 2008,Tsql,为什么我不能这样做: declare @myTempTableList TABLE ( CommId int ) insert into @myTempTableList (CommId) VALUES (742), (803) delete from myRealTable where MyRealTableId in ( select mrt.MyRealTableId from MyRealTable mrt where commId in (@myTempTableL
declare @myTempTableList TABLE (
CommId int
)
insert into @myTempTableList (CommId)
VALUES
(742), (803)
delete from myRealTable where MyRealTableId in (
select mrt.MyRealTableId from MyRealTable mrt
where commId in (@myTempTableList)
)
它告诉我,我必须声明标量变量@MyTestableList
delete from myRealTable where MyRealTableId in (
select mrt.MyRealTableId from MyRealTable mrt
where commId in (SELECT CommId FROM @myTempTableList)
)
试试上面的方法
DELETE FROM myRealTable
WHERE EXISTS (SELECT 1
FROM @myTempTableList
WHERE myRealTable.MyRealTableId = @myTempTableList.CommId)