日期:2014-05-17 浏览次数:20603 次
DECLARE @i NVARCHAR(2000)
SET @i ='AAAAxxBBBBBBBxxCCCCxxDDDDDDDDDDDxxEEEEEExxFFFFFFFFFF'
SELECT SUBSTRING(@i,0,CHARINDEX('xx',@i,CHARINDEX('xx',@i,CHARINDEX('xx',@i)+1)+1))
--AAAAxxBBBBBBBxxCCCC
DECLARE @split VARCHAR(20),@i INT,@result VARCHAR(4000)
SET @split='xx'
SET @i=3
DECLARE @xml XML
DECLARE @str VARCHAR(4000)
SET @str='AAAAxxBBBBBBBxxCCCCxxDDDDDDDDDDDxxEEEEEExxFFFFFFFFFF'
set @xml='<value>'+REPLACE(@str,@split,'</value><value>')+'</value>'
SET @result=stuff(CAST( (SELECT @split+result FROM(
SELECT
T.C.value('.','VARCHAR(200)') AS result,flag=ROW_NUMBER() OVER (ORDER BY @xml.query('.').value('.','VARCHAR(4000)'))
from @xml.nodes('/value') T(C))g
WHERE flag<@i+1
FOR XML PATH('') )AS VARCHAR(max)),1,LEN(@split),'')
SELECT @result