SQL Server:将整数列表插入临时表

Ev.*_*Ev. 5 sql-server

我在文本文件中有一个 ID 列表,如下所示:

24641985 ,
24641980 ,
24641979 ,
24641978 ,
24641976 ,
24641974 ,
...
...
24641972 ,
24641971 ,
24641970 ,
24641968 ,
24641965)
Run Code Online (Sandbox Code Playgroud)

有数以万计。

现在我需要知道此列表中的哪些 ID 与我表中的 ID 不对应。

我想我应该把它们放在一个临时表中,然后说:

select theId 
  from #tempIdCollection
 where theId not in (select customerId from customers)
Run Code Online (Sandbox Code Playgroud)

问题是我不知道如何将它们放入临时表!

任何人都可以帮忙吗?这不一定是高效的。我只需要运行一次。欢迎任何解决方案建议!

提前致谢!

-Ev

Kir*_*rst 4

我会使用表变量。您可以像常规变量一样声明它。

declare @tempThings table (items int)
insert @tempThings values (1)
Run Code Online (Sandbox Code Playgroud)