如果在SQL查询中返回null,则返回默认图像 [英] Return default image if it return null in SQL Query

查看:166
本文介绍了如果在SQL查询中返回null,则返回默认图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..朋友,我有一个表,该表具有SQL Server 2005中的simage列,名称为tbStudent.我编写了一个查询

Hi.. friends I have a table having column simage, sname name tbStudent in SQL server 2005. I write a query

select simage,sname from tbStudent

,但有些学生没有图像,因此返回空值.我希望它为那些没有图像的学生返回默认图像.那么查询将是什么.请帮我.我很困惑.


谢谢&提前考虑
Parveen Rathi

but some student has no image so it return the null value. I wants that it return a default image for those student who have no image. So what will be the query. Please help me. I am very confused.


Thanks & Regards in advance
Parveen Rathi

推荐答案

如果其他表中包含默认图像,则可以将该表加入查询中,例如,通过合并功能在必要时选择默认图像.例如:
If the default image is in some other table you can join that table into your query and for example with coalesce function select the default when necessary. For example something like:
select coalesce (a.simage, b.defaultimagefield) 
from tbstudent a, tablewithdefaultimage b ...


您可以有一个临时表,其中单个图像值表示为空图片,然后使用以下查询..

you can have a temporary table with single image value represents empty image then use the following query..

SELECT (CASE WHEN simage IS NULL THEN (SELECT emptyImage FROM TEMP_TABLE)ELSE simage END),sname from tbStudent



希望对您有所帮助.



Hope it helps..


尝试一下,

Try this,

SELECT    ISNULL(simage, [defaulimage])
         ,sname
FROM      tbStudent



如果这解决了您的问题,请标记为答案并投票5

最好的问候,
爱德华



Please mark as answer and vote 5 if this solved your problem

Best regards,
Eduard


这篇关于如果在SQL查询中返回null,则返回默认图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆