Time:05-12
1,4,11,23,32,55 3 5 11 12 21 and 27 11,15,21,23,27,39 1,2,3,4,5,9 3,5,11,12,21,27 11 15 21, 23 and 27 39 1 2 3 4 5 39 22 and 24, 25, 29, 31 and 32 1 4 November 23 32 to 55
notext 01, 02, 03 04 05 09 01, 02, 03 04 05 39 01 04 11 23 32 to 55 03 05 November 12 21 27 11 15 21, 23 and 27 39 22 and 24, 25, 29, 31 and 32
If object_id (' tempdb for. Dbo. # test1 ') is not null drop table # test1 Go The create table # test1 ([notext] nvarchar (20)) DECLARE @ SQL NVARCHAR (MAX), @ INT I; SELECT @ SQL=N '@ I=119; WHILE @ I & gt; 0 The BEGIN The SET @ SQL=N 'BULK INSERT # test1 FROM' 'E: \ LOTTData \ hellome \' + CONVERT (VARCHAR (2), @ I) + N ". TXT "' WITH (FIELDTERMINATOR=' ' ' ', ROWTERMINATOR='\ n' ) '; PRINT @ SQL; The EXEC (@ SQL); The SET @ I=@ I - 1; END;
CodePudding user response:
DECLARE @ t TABLE (Note NVARCHAR (MAX)) INSERT the @ t (Note) VALUES ,4,11,23,32,55 (' 1 '), (' 3 5 11 12 21 and 27), (' 11,15,21,23,27,39), ,2,3,4,5,9 (' 1 '), (' 3,5,11,12,21,27), (' 11 15 21, 23 and 27 39), 39 '(' 1, 2, 3, 4, 5), (' 22 and 24 25 29, 31 and 32), (' 1 4 November 23 32 to 55) SELECT the REPLACE (REPLACE (Note, 'and', '), ', ', ') Note, S.N ewNote The FROM @ t t The OUTER APPLY (SELECT CASE WHEN LEN (newNote. Value)=1 THEN '0' + newNote. Value The ELSE '+ newNote. Value END The FROM STRING_SPLIT (REPLACE (REPLACE (note, 'and', '), ', ', '), ' ') AS newNote FOR XML PATH (') S (NewNote); - remove the duplicates SELECT DISTINCT S.N ewNote The FROM @ t t The OUTER APPLY (SELECT CASE WHEN LEN (newNote. Value)=1 THEN '0' + newNote. Value The ELSE '+ newNote. Value END The FROM STRING_SPLIT (REPLACE (REPLACE (note, 'and', '), ', ', '), ' ') AS newNote FOR XML PATH (') S (NewNote);
- remove the duplicates SELECT DISTINCT STUFF (S.N ewNote, 1, 1, ' ') AS NewNote The FROM @ t t The OUTER APPLY (SELECT CASE WHEN LEN (newNote. Value)=1 THEN '0' + newNote. Value The ELSE '+ newNote. Value END The FROM STRING_SPLIT (REPLACE (REPLACE (note, 'and', '), ', ', '), ' ') AS newNote FOR XML PATH (') S (NewNote);
after import data processing: [code=SQL] DECLARE @ t TABLE (Note NVARCHAR (MAX)) INSERT the @ t (Note) VALUES ,4,11,23,32,55 (' 1 '), (' 3 5 11 12 21 and 27), (' 11,15,21,23,27,39), ,2,3,4,5,9 (' 1 '), (' 3,5,11,12,21,27), (' 11 15 21, 23 and 27 39), 39 '(' 1, 2, 3, 4, 5), (' 22 and 24 25 29, 31 and 32), (' 1 4 November 23 32 to 55) SELECT the REPLACE (REPLACE (Note, 'and', '), ', ', ') Note, S.N ewNote The FROM @ t t
message 208, level 16, state 1, line 8 Object name 'STRING_SPLIT' invalid,
create function f_split (@ SourceSql varchar (8000), @ StrSeprate varchar (10)) Returns the @ temp table (a varchar (100)) , realizing the function of the split function - date: 2018-5-14 As The begin Declare @ I int The set @ SourceSql=rtrim (ltrim (@ SourceSql)) The set @ I=charindex (@ StrSeprate, @ SourceSql) While @ i>=1 The begin Insert the @ temp values (left (@ SourceSql, @ I - 1)) Set @ SourceSql=the substring (@ SourceSql, @ I + 1, len (@ SourceSql) - @ I) The set @ I=charindex (@ StrSeprate, @ SourceSql) End If @ SourceSql<> 'Insert the @ temp values (@ SourceSql) Return End
Page link:https//www.codepudding.com/database/110844.html