我需要从表中删除某些行,其中索引是表变量
中的相等索引 declare @m_table as table
(
number NUMERIC(18,0)
)
...
inserting some rows into @m_table
...
DELETE ct FROM [dbo].[customer_task] ct
inner join project_customer pc on pc.id_customer = @m_table.number
inner join customer_user cu on cu.id_project_customer = pc.id
WHERE ct.id_csr_user = cu.id AND ct.id_status = 1;
但是此代码会生成错误:必须声明标量变量“@m_table”如何解决?
答案 0 :(得分:2)
你可能在那些'...'
中有一个'GO
'(批处理分隔符)
变量声明不会跨越批次。
答案 1 :(得分:1)
错误意味着SQL希望您将@m_table
视为标准表,而不是标量(int,bit等)变量。也许这样的事情会起作用吗?
DELETE ct FROM [dbo].[customer_task] ct
WHERE ct.id_csr_user IN (
SELECT cu.id FROM customer_user cu
INNER JOIN project_customer pc ON pc.id = cu.id_project_customer
WHERE pc.id_customer IN (SELECT number FROM @m_table.number)
) AND ct.id_status = 1;