Click here to Skip to main content
14,982,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.. friends I have a table having column simage, sname name tbStudent in SQL server 2005. I write a query
SQL
select simage,sname from tbStudent
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
Posted

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:
SQL
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..

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


Hope it helps..
   
Try this,

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


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

Best regards,
Eduard
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900