1

我需要从表中删除一些索引与表变量中的索引相等的行

  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”如何解决?

4

2 回答 2

2

您可能GO在那些“...”中有一个“”(批处理分隔符)

变量声明不跨越批次。

于 2010-08-19T07:07:38.563 回答
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;
于 2010-08-19T07:09:48.413 回答