declare @str nvarchar(1000)
declare @strHZ nvarchar(max)
set @strHZ=''
set @str='<top:28.324;left:20.409;"><nobr>
<span style="font-size:9.111;">Printed:</span>
<span style="font-size:9.111;">09-Jul-2014</span>
<span style="font-size:9.111;">19:59:17</span>
</nobr></div>'
;with ctes
as
(
select snum,row_number() over(order by snum) as 序号
from
(
select distinct charindex ('<span style="font-size:9.111;">',@str,number)+LEN('<span style="font-size:9.111;">') as snum from master.dbo.spt_values where type='p'
) as s
)
,ctee
as
(
select enum,row_number() over(order by enum) as 序号
from
(
select distinct charindex ('</span>',@str,number) as enum from master.dbo.spt_values where type='p'
) as s
)
select @strHZ=@strHZ+SUBSTRING(@str,a.snum,b.enum-a.snum) from ctes a inner join ctee b on a.序号=b.序号 and b.enum>0
print @strHZ
--加一个分隔函数:
create function F_split(
@s varchar(8000), --包含多个数据项的字符串
@pos int, --要获取的数据项的位置
@split varchar(10) --数据分隔符
)RETURNS varchar(100)
AS
BEGIN
IF @s IS NULL RETURN(NULL)
DECLARE @splitlen int --分隔符长度
SELECT @splitlen=LEN(@split+'a')-2
WHILE @pos>1 AND charindex(@split,@s+@split)>0
SELECT @pos=@pos-1,
@s=stuff(@s,1,charindex(@split,@s+@split)+@splitlen,'')
RETURN(nullif(left(@s,charindex(@split,@s+@split)-1),''))
END
GO
DECLARE @text varchar(max)
SET @text = '<top:28.324;left:20.409;"><nobr>
<span style="font-size:9.111;">Printed:</span>
<span style="font-size:9.111;">09-Jul-2014</span>
<span style="font-size:9.111;">19:59:17</span>
</nobr></div>';
select dbo.F_split(replace(@text,'<span style="font-size:9.111;">','</span>'),2,'</span>')+
dbo.F_split(replace(@text,'<span style="font-size:9.111;">','</span>'),4,'</span>')+' '+
dbo.F_split(replace(@text,'<span style="font-size:9.111;">','</span>'),6,'</span>')
drop function F_split
--加一个分隔函数:
create function F_split(
@s varchar(8000), --包含多个数据项的字符串
@pos int, --要获取的数据项的位置
@split varchar(10) --数据分隔符
)RETURNS varchar(100)
AS
BEGIN
IF @s IS NULL RETURN(NULL)
DECLARE @splitlen int --分隔符长度
SELECT @splitlen=LEN(@split+'a')-2
WHILE @pos>1 AND charindex(@split,@s+@split)>0
SELECT @pos=@pos-1,
@s=stuff(@s,1,charindex(@split,@s+@split)+@splitlen,'')
RETURN(nullif(left(@s,charindex(@split,@s+@split)-1),''))
END
GO
DECLARE @text varchar(max)
SET @text = '<top:28.324;left:20.409;"><nobr>
<span style="font-size:9.111;">Printed:</span>
<span style="font-size:9.111;">09-Jul-2014</span>
<span style="font-size:9.111;">19:59:17</span>
</nobr></div>';
select dbo.F_split(replace(@text,'<span style="font-size:9.111;">','</span>'),2,'</span>')+
dbo.F_split(replace(@text,'<span style="font-size:9.111;">','</span>'),4,'</span>')+' '+
dbo.F_split(replace(@text,'<span style="font-size:9.111;">','</span>'),6,'</span>')
drop function F_split
declare @s varchar(max)
set @s= '<top:28.324;left:20.409;"><nobr>
<span style="font-size:9.111;">Printed:</span>
<span style="font-size:9.111;">09-Jul-2014</span>
<span style="font-size:9.111;">19:59:17</span>
</nobr></div>'
;with cte as
(
select row_number () over ( order by snum desc )as rn1,snum
from (
select distinct charindex ('">',@s,number) as snum from master.dbo.spt_values where type='p' and number >=1 and number <len (@s)
)t
)
,cte1 as
(
select row_number () over ( order by enum desc )as rn2,enum
from (
select distinct charindex ('</span>',@s,number) as enum from master.dbo.spt_values where type='p' and number >=1 and number <len (@s)
)t2
)
select substring (@s,cte.snum +2,cte1.enum-cte.snum-2) from cte
inner join cte1 on cte.rn1=cte1.rn2 where cte.snum<>0 and cte1.enum<>0
--(无列名)
--19:59:17
--09-Jul-2014
--Printed:
能处理成Printed:09-Jul-2014 19:59:17吗[/quote]
declare @s varchar(max)
set @s= '<top:28.324;left:20.409;"><nobr>
<span style="font-size:9.111;">Printed:</span>
<span style="font-size:9.111;">09-Jul-2014</span>
<span style="font-size:9.111;">19:59:17</span>
</nobr></div>'
;with cte as
(
select row_number () over ( order by snum desc )as rn1,snum
from (
select distinct charindex ('">',@s,number) as snum from master.dbo.spt_values where type='p' and number >=1 and number <len (@s)
)t
)
,cte1 as
(
select row_number () over ( order by enum desc )as rn2,enum
from (
select distinct charindex ('</span>',@s,number) as enum from master.dbo.spt_values where type='p' and number >=1 and number <len (@s)
)t2
)
select substring (@s,cte.snum +2,cte1.enum-cte.snum-2) from cte
inner join cte1 on cte.rn1=cte1.rn2 where cte.snum<>0 and cte1.enum<>0 for xml path('')
--19:59:1709-Jul-2014Printed:[/quote]XML没弄过。。还有别的方法吗
-- 先得把 <nobr> .. </nobr> 这一段提取出来,然后用 xml 进行处理
DECLARE @text varchar(max)
DECLARE @i1 int
DECLARE @i2 int
SET @text = '<top:28.324;left:20.409;"><nobr>
<span style="font-size:9.111;">Printed:</span>
<span style="font-size:9.111;">09-Jul-2014</span>
<span style="font-size:9.111;">19:59:17</span>
</nobr></div>';
SET @i1 = CharIndex('<nobr>',@text,1)
SET @i2 = CharIndex('</nobr>',@text,1)
DECLARE @myDoc xml
SET @myDoc = SubString(@text,@i1,@i2-@i1+Len('</nobr>'))
SELECT T.c.value('.','varchar(20)')
FROM @myDoc.nodes('/nobr/span') T(c)
for xml path('')
declare @s varchar(max)
set @s= '<top:28.324;left:20.409;"><nobr>
<span style="font-size:9.111;">Printed:</span>
<span style="font-size:9.111;">09-Jul-2014</span>
<span style="font-size:9.111;">19:59:17</span>
</nobr></div>'
;with cte as
(
select row_number () over ( order by snum desc )as rn1,snum
from (
select distinct charindex ('">',@s,number) as snum from master.dbo.spt_values where type='p' and number >=1 and number <len (@s)
)t
)
,cte1 as
(
select row_number () over ( order by enum desc )as rn2,enum
from (
select distinct charindex ('</span>',@s,number) as enum from master.dbo.spt_values where type='p' and number >=1 and number <len (@s)
)t2
)
select substring (@s,cte.snum +2,cte1.enum-cte.snum-2) from cte
inner join cte1 on cte.rn1=cte1.rn2 where cte.snum<>0 and cte1.enum<>0
--(无列名)
--19:59:17
--09-Jul-2014
--Printed:
能处理成Printed:09-Jul-2014 19:59:17吗[/quote]
declare @s varchar(max)
set @s= '<top:28.324;left:20.409;"><nobr>
<span style="font-size:9.111;">Printed:</span>
<span style="font-size:9.111;">09-Jul-2014</span>
<span style="font-size:9.111;">19:59:17</span>
</nobr></div>'
;with cte as
(
select row_number () over ( order by snum desc )as rn1,snum
from (
select distinct charindex ('">',@s,number) as snum from master.dbo.spt_values where type='p' and number >=1 and number <len (@s)
)t
)
,cte1 as
(
select row_number () over ( order by enum desc )as rn2,enum
from (
select distinct charindex ('</span>',@s,number) as enum from master.dbo.spt_values where type='p' and number >=1 and number <len (@s)
)t2
)
select substring (@s,cte.snum +2,cte1.enum-cte.snum-2) from cte
inner join cte1 on cte.rn1=cte1.rn2 where cte.snum<>0 and cte1.enum<>0 for xml path('')
--19:59:1709-Jul-2014Printed:
--加一个分隔函数:
create function F_split(
@s varchar(8000), --包含多个数据项的字符串
@pos int, --要获取的数据项的位置
@split varchar(10) --数据分隔符
)RETURNS varchar(50)
AS
BEGIN
IF @s IS NULL RETURN(NULL)
DECLARE @splitlen int --分隔符长度
declare @temp varchar(1000)
SELECT @splitlen=LEN(@split )
WHILE @pos>1 AND charindex(@split,@s+@split)>0
begin
SELECT @pos=@pos-1,
@s=stuff(@s,1,charindex(@split,@s+@split)+@splitlen,'')
end
if (charindex(@split,@s+@split)-1 > 0 ) and (charindex(@split,@s+@split)-1< len(@s))
begin
set @temp = REVERSE((nullif(left(@s,charindex(@split,@s+@split)-1),'')))
set @temp = REVERSE(left(@temp,charindex('>";',@temp)-1))
end
else
set @temp = ''
RETURN @temp
END
GO