sql >> Database teknologi >  >> RDS >> Sqlserver

Opdel sql-streng i ord

Prøv dette:

declare @s1 varchar(3000) ;
declare @xml xml,@str varchar(100),@delimiter varchar(10), @out varchar(max);;
select @delimiter =' '
select @s1 =  'This is a string';
select @s1 = 'This    is   a   string ';
select @s1 = 'This  is a          string ';
select @s1 = 'This  is           a string';

select @xml = cast(('<X>'+replace(@s1,@delimiter ,'</X><X>')+'</X>') as xml)

select top 3 @out = 
    COALESCE(@out + ' ', '') +  C.value('.', 'varchar(100)') 
from @xml.nodes('X') as X(C)
where LEN(C.value('.', 'varchar(10)')) > 0

select @out


  1. Heltalsopdeling i sql-server

  2. Bemærk:Konvertering af matrix til streng i

  3. mysql regex_replace:hvordan man bruger regex-gruppen som erstatning

  4. PDO MySQL-driver på Mac