34,837
社区成员




如果要简洁,二楼的已经够了。
楼主是要将你的改成这样?
declare @sex nvarchar(50)
select @sex = TitleOfCourtesy from dbo.Employees where EmployeeID = 5
select case @sex
when 'Ms.' then '女士'
when 'Mr.' then '男士'
else 'nothing' end
还是:
declare @sex nvarchar(50)
select @sex = TitleOfCourtesy from dbo.Employees where EmployeeID = 5
if(@sex='Ms.') print '女士'
if(@sex='Mr.') print '男士'
else print 'nothing'
select TitleOfCourtesy = case TitleOfCourtesy when 'Ms.' then 女士' when 'Mr.' then '男士' end from dbo.Employees
declare @sex nvarchar(50)
select top 1 @sex = TitleOfCourtesy from dbo.Employees
print @sex
--case 的使用
declare @sex nvarchar(50)
select top 1 @sex = TitleOfCourtesy from dbo.Employees
where EmployeeID = 5
select case @sex
when 'Ms.' then print'女士'
when 'Mr.' then print'男士'
else print'nothing'
end