现在的位置: 首页 > 综合 > 正文

charindex and stuff(转)

2012年03月21日 ⁄ 综合 ⁄ 共 533字 ⁄ 字号 评论关闭

Create Table 留言表
(id Int,
 title Varchar(100),
 content Varchar(1000))
Insert 留言表 Select 1, 'A', 'ABC<img src="1.jpg" width=xx height=xx>zz'
Union All Select 2, 'B', 'dsad'
Union All Select 3, 'C', 'KKK<img src="2.jpg" width=xx height=xx>'
Union All Select 4, 'D', 'MM<img src="3.jpg" width=xx height=xx>'
Union All Select 5, 'E', 'KKK'

select * from 留言表
GO
--測試
Select id, title,
(Case When CharIndex('<img src', content) > 0 Then
Stuff(content, CharIndex('<img src', content), CharIndex('>', content, CharIndex('<img src', content) + 1) - CharIndex('<img src', content) + 1, '')
Else content End)  As content From 留言表
Gop

抱歉!评论已关闭.