Use Tempdb
- Establish a temporary table to save each string if exists (select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Table1]') And ObjectProperty (ID, n'uSERTABLE ') = 1) Drop Table [ DBO]. [TABLE1] GO
Create Table [DBO]. [Table1] ([COL1] [varchar] (100) collate chinese_prc_ci_as null) on [primary] Go
Declare @teststring varchar (1000) Declare @ teststring1 varchar (200) - a separate string Declare @ Testi1 int - The first-character character, comma position set @teststring = '1, 22, 333, 4444, 55555 ?set @ Testi1 = 1set @ Teststring1 = '' print len (@teststring) While @ Testi1 <= len (@teststring) Begin if Substring (@teststring, @ Testi1, 1) = ',' Begin Insert Into Table1 (Col1) VALUES @ Teststring1) Set @ Teststring1 = '' end else begin set @ Teststring1 = @ Teststring1 Substring (@teststring, @ Testi1, 1) end set @ Testi1 = @ Testi1 1END
IF @ Teststring1 <> '' INSERT INTO TABLE1 (COL1) VALUES (@ Teststring1) Go