新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SQLServer拆分字符串的3常用種方法
以下的文章主要是介紹的是SQL Server拆分字符串的3常用種方法,我前兩天在相關網(wǎng)站看見SQL Server拆分字符串的3常用種方法的資料,覺得挺好,就拿出來供大家分享,望會給大家?guī)硪恍椭诖朔矫妗?/p>

- use tempdb
- use tempdb
- go
測試數(shù)據(jù)
- declare @s varchar(1000)
- set @s='ak47,mp5,1,23'
要求輸出結(jié)果
- S
- ak47
- mp5
- 1
- 23
SQL Server拆分字符串的3種方法對比:
SQL Server拆分字符串1.[樸實]動態(tài)Exec方法:
- declare @s1 varchar(1000)
- set @s1=right(replace(','+@s,',',''' as S union select '''),len(replace(','+@s,',',''' as S union select '''))-12)+''''
- exec(@s1)
SQL Server拆分字符串2.[變通]表交叉方法:
- select replace(reverse((left(s,charindex(',',s)))),',','') as S from(
- select r,reverse(left(@s,r))+',' as s
- from(
- select (select count(*) from sysobjects where name<=t.name ) as r
- from sysobjects t
- )a where r<=len(@s)
- and left(@s+',',r+1) like '%,'
- )t order by r
SQL Server拆分字符串3.[高級]XML方法:
- DECLARE @idoc int;
- DECLARE @doc xml;
- set @doc=cast('
' as xml) '+replace(@s,',','')+'- EXEC sp_xml_preparedocument @Idoc OUTPUT, @doc
- SELECT * FROM OPENXML (@Idoc, '/Root/item',2)
- WITH (
- [S] varchar(10)
- )
以上的相關內(nèi)容就是對SQL Server拆分字符串的三種方法的介紹,望你能有所收獲。
【編輯推薦】
- SQL Server 2005 synonyms的優(yōu)缺點有哪些?
- SQL Server快照功能以及其查詢操作
- SQL Server行轉(zhuǎn)列的什么情況下被用?
- SQL Server排序遇到NULL,不怕不帕!
- SQL Server 2005兩種快照隔離機制的不同之處
分享標題:SQLServer拆分字符串的3常用種方法
標題網(wǎng)址:http://m.fisionsoft.com.cn/article/cdheejp.html


咨詢
建站咨詢
