当我有大量ID时,如何在SQL Server中创建临时表 [英] How would I create a temp table in SQL Server when I have a big list of ID's

查看:172
本文介绍了当我有大量ID时,如何在SQL Server中创建临时表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个原始ID列表,应该将它们放入临时表中。我不确定这在SQL Server中的工作方式:

I have a list of raw IDs that I am supposed to put into a temp table. I am unsure about how this works in SQL Server:

我知道一般格式:

select PID into #myPIDs
from ... ?

我已经有大约30个要使用的PID的列表。它们看起来像这样:

I already have a list of about 30 PIDs which I am to use. They look like so:

'U388279963',
'U388631403',
'U389925814'

我该怎么做?谢谢!

推荐答案

您的格式将可以为一个插入创建新的临时表。如果您需要复制并粘贴ID,则可以使用以下内容。

Your format will work for creating a new temp table for one insert. If you need to copy and paste your IDs then the following will work.

CREATE TABLE #myPIDs
(
     PID VARCHAR(30)
);

INSERT INTO #myPIDs
VALUES
(....),
(....);

复制并粘贴您的PID,并使用find和replace和正则表达式将每行替换为正则表达式选项已选中。删除最后一个','就好了。

Copy and paste your PIDs and use find and replace with regular expressions to replace each line with the regular expression option checked. Remove the last ',' and you're good.


查找-^ {U:​​z +} $

Find - ^{U:z+}$

替换-('\1'),\n

Replace - ('\1'),\n

或者您可以拥有sql server从系统上的文件中读取您的ID。如果您详细说明您的需求,我可以为您提供更好的答案。

Alternatively you can have sql server read your ids from a file on the system. If you elaborate on your needs I can give you a better answer.

这篇关于当我有大量ID时,如何在SQL Server中创建临时表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆