Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 删除ID在#中的行_Sql Server_Sql Server 2008_Tsql - Fatal编程技术网

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)