字段是
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'
答案 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