Reply to: smalldeer (晓露) () Reputation: 100 2004-7-2 10:48:38 Score: 0
/ *
String split function
- Call example
Select * from dbo.fsplit ('a; adf; fd; ed; dh', ';')
Select * from dbo.fsplit ('A, ADF, FD, ED, DH', ', ")
Zou Jian 2003.07 * /
- Check if the function exists if EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Fsplit]') and xtype in (n'fn ', n'if ", n't') ) Drop Function [dbo]. [Fsplit] Go
- Creating string splitting function crete function fsplit (@str varchar (8000) - String to split, @ spli varchar (10) - string divider) Returns @re table (istr varchar (8000 )) asbegin declare @i int, @ splen int select @ splen = len (@spli), @ i = charindex (@ spli, @ str) while @i> 0 begin insert @re value (@ Str, @ @ @ @ @ @ I-1)) SELECT @ Str = Substring (@ Str, @ i @ splen, 8000), @ i = charindex (@ spli, @ Str) end if @str <> 'INSERT INTO @re value (@STR) Returned
Select * from dbo.fsplit (123 | ABC | 000 | 777 ',' | ')
Reply to: Smalldeer (晓露) () Reputation: 100 2004-7-2 10:49:14 Score: 0
The above is Zou Jian's
I use declare @String varchar (1000) set @ String = '123 | ABC | 000 | 777'Set @ String =' SELECT * INTO ## TMP from (SELECT '' Replace (@string, '|', '' AS STR Union All SELECT '' ') ' '') A 'Exec (@string)
Select * from ## tmpdrop Table ## TMP