May 19, 2008 at 4:34 pm
Hi everyone, I have found myself in a hurry of needing to find a sql server function to split words? Like the split function in C#??
For example if I pass to the function a sentence, it should return just the words :hehe: or how could I do this? maybe using a cursor?? or a temp table? Any ideas or suggestions are accepted Thanks in advance.
May 19, 2008 at 4:41 pm
May 19, 2008 at 7:53 pm
i've become very dependent on this:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[fListToVarchars]( @list varchar(max), @delim varchar(6) )
returns @returnTable table
( item varchar(255) not null, itemSequence smallint not null )
as begin
declare @xml XML
set @xml = char(60)+'item>' + REPLACE(REPLACE(@list,char(60),'<'),@delim,char(60)+'/item>'+char(60)+'item>') + char(60)+'/item>'
insert into @returnTable
SELECT data.item.value('.','varchar(255)'), row_number() over (order by getdate())
FROM @xml.nodes('//item') as data(item)
return
end
;
usage:
select * from dbo.fListToVarchar('mary had a little lamb.',' ');
May 20, 2008 at 1:02 am
I've found XML splits to be just a tad on the slow side. Take a look at the following URL.
http://www.sqlservercentral.com/articles/TSQL/62867/
Also, fairly big article on splits coming out on Wednesday.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy