我有一个包含4个字段的小型注册表

时间:2016-11-15 10:43:11

标签: c# sql

字段是

employeeID  int 
name  varchar
Gender int  (0 = male, 1 = female)
Date datetime

现在如果我正在写这样的选择查询

select employeeID,name,Gender,Date 
from empTable 
where employeeID=@id

我得到了结果

'101','cccc','1','11/1/2014'

但我需要一个查询它给我

'101','cccc','Female','11/1/2014'

1 个答案:

答案 0 :(得分:1)

如果这是Sql Server,您可以使用CASE语句。

select employeeID
  ,name
  ,case when Gender = 1 then 'Female' else 'Male' end AS Gender
  ,Date 
from empTable 
where employeeID=@id

IIF声明

select employeeID
  ,name
  , IIF(Gender = 1, 'Female', 'Male') AS Gender
  ,Date 
from empTable 
where employeeID=@id