sql中加判断的语句如何写?

来源:百度知道 编辑:UC知道 时间:2024/05/14 04:20:19
我有一个新闻表news,其中有字段 id,title,contents。字段contents是新闻的内容。
我现在要列出所有新闻标题,如果内容里包含有图片的话(包含img标记),在列出新闻标题的时候后面加个“图”字,没有的不显示,也就是加一个判断标记字段,SQL语句应该怎么写呢?(存储过程我不会)
我想列出新闻时只调出ID,title,两个字段,因为contents字段太长了,不便操作,
Select id,title,flag(这个做标记) from news where contents like '%img%'
就这是个flag怎么产生!

按你的意思就是判断"contents"里有没有"img"这一字符串
<%
mg=Instr(rs("contents"),"img")
mg2=Instr(rs("contents"),"image")
if mg=0 and mg2=0 then '说明contents中没有 img 和 image
response.write "无图"
else
response.write "图"
end if
%>

将这个代码放你要写"图"字的地方.

刚改了!~

你这样判断根本就不严密 图片的是:<img> 要是别人写个单词image你还以为有图片呢 至少要是<img这个吧
最好把中间空格去掉