paoluo帖

来源:互联网 发布:手机淘宝积分怎么看 编辑:程序博客网 时间:2024/05/02 01:27
--創建測試環境
Create Table 留言表
(id Int,
 title Varchar(100),
 content Text)
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'
GO
--測試
Select id, title,
(Case When CharIndex('<img src', content) > 0 Then
Substring(content, 1, CharIndex('<img src', content) - 1)
+ Substring(content, CharIndex('>', content, CharIndex('<img src', content) + 1) + 1, DataLength(content))
Else content End)  As content From 留言表
Gop
--刪除測試環境
Drop Table 留言表
--結果
/*
idtitlecontent
1AABCzz
2Bdsad
3CKKK
4DMM
5EKKK
*/