sql查询语句如下

来源:百度知道 编辑:UC知道 时间:2024/05/23 16:35:15
select ArticleID,ChannelID,ClassID,Title,Author,Hits,UpdateTime,DefaultPicUrl,Stars from PE_Article where ArticleID={input(0)}如何让它在DefaultPicUrl不存在的时候显示另外一张图片????添加成select ArticleID,ChannelID,ClassID,Title,Author,Hits,UpdateTime,DefaultPicUrl,Stars from PE_Article where ArticleID={input(0)} and DefaultPicUrl is not null order by ArticleID desc也不行
用if ??不知道格式是怎样的。。。请给出解答。。

在SQL server里直接用is not null 是不行的,null函数有两个参数,可以尝试做修改如下:
ArticleID,ChannelID,ClassID,Title,Author,Hits,UpdateTime,DefaultPicUrl,Stars from PE_Article where ArticleID={input(0)} and isnull(DefaultPicUrl,1) <>1 order by ArticleID desc

其他我看不出问题。
DefaultPicUrl is not null 判断图片链接不存在的方法是有问题的,空格问题是最常见的。
改成rtrim(DefaultPicUrl)!=''试试

ISNULL
使用指定的替换值替换 NULL。
语法
ISNULL ( check_expression , replacement_value )

参数
check_expression

将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。

replacement_value

在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。

返回类型
返回与 check_expression 相同的类型。

注释
如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。