How to create a temporary table in SQL Server when I have a large list of identifiers

I have a list of raw identifiers that I should put in the temp table. I am not sure how this works in SQL Server:

I know the general format:

select PID into #myPIDs from ... ? 

I already have a list of 30 PIDs that I should use. They look like this:

 'U388279963', 'U388631403', 'U389925814' 

How can I do it? Thanks!

+6
source share
2 answers

Your format will work to create a new temp table for one insert. If you need to copy and paste identifiers, then the following will work.

 CREATE TABLE #myPIDs ( PID VARCHAR(30) ); INSERT INTO #myPIDs VALUES (....), (....); 

Copy and paste your PIDs and use regular expression search and replace to replace each line with the regular expression option. Delete the last ',' and you are good.

Find - ^ {U: z +} $

Replace - ('\ 1'), \ n

Alternatively, you can force the sql server to read your identifiers from a file on the system. If you talk in detail about your needs, I can give you a better answer.

+6
source
 insert into #myPIDs (ID) select 'U388279963' union select 'U388631403' union select 'U389925814' 
+4
source

Source: https://habr.com/ru/post/922874/


All Articles