如何在Sql中的select语句中替换列值?

时间:2014-08-27 10:36:55

标签: c# sql sql-server

我正在尝试编写一个查询,我希望将列值替换为Available,如果它不为空,否则不可用。

select CandidateID,ResumeName from dbo.Tbl_Candidates 
where CreatedBy=UserId order by CandidateID DESC 

在这种情况下,如果ResumeName不为空,我想替换为Available else Not Available。这有助于我解决这个问题。提前谢谢。

4 个答案:

答案 0 :(得分:7)

select CandidateID, case when ResumeName = '' Then 'Not Available' Else 'Available' End as Availability 
from dbo.Tbl_Candidates 
where CreatedBy=UserId 
order by CandidateID DESC 

答案 1 :(得分:1)

select CandidateID,
case 
   when ResumeName is null then 'Not Available'
   when ResumeName = '' then 'Not Available'
   else 'Available'
end as ResumeName from dbo.Tbl_Candidates 
where CreatedBy=UserId order by CandidateID DESC 

答案 2 :(得分:1)

SELECT CandidateID,CASE WHEN ISNULL(ResumeName,'') = '' 'Not Available' ELSE 'Available' END AS ResumeAvailability from dbo.Tbl_Candidates 
where CreatedBy=UserId order by CandidateID DESC  

答案 3 :(得分:0)

select CandidateID,ISNULL(ResumeName,'Not Available') as ResumeName    
 from dbo.table 
where CreatedBy=UserId order by CandidateID DESC