Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

sql - INSERT INTO TABLE from comma separated varchar-list

Maybe i'm not seeing the wood for the trees but i'm stuck, so here's the question:

How can i import/insert a list of comma separated varchar-values into a table? I don't mean something like this:

  • '12345678,87654321,11223344' but this:
  • '12345678','87654321','11223344'

I have a Split-Function but it seems to be useless in this case, isn't it?

Here is a simple (mock-SQL) example to show what i mean:

Create Table #IMEIS(
    imei varchar(15)
)
INTO INTO #IMEIS(imei)
    SELECT * FROM ('012251000362843', '012251001084784', '012251001168744', '012273007269862', '012291000080227', '012291000383084', '012291000448515')
SELECT * from #IMEIS
DROP TABLE #IMEIS;

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Something like this should work:

INSERT INTO #IMEIS (imei) VALUES ('val1'), ('val2'), ...

UPDATE:

Apparently this syntax is only available starting on SQL Server 2008.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...