1

我有一张桌子叫Tb_patientBeds.

现在我想根据该表中的列检索设置为占用未占用或全部的记录。status

这是我的其他专栏:

patientBedID int IDENTITY(1,1) NOT NULL,
patientBedType [varchar](20) NULL,
BedCharge [varchar](20) NULL,
status [varchar](20) NULL,

我写了这样的查询

select * from Tb_patientBeds where [status]= case
when [status]= '0'
then 'occupied'
when [status]='1'
then 'unoccupied' else 'All'
end

查询没有返回记录,它显示的是空记录。

有人可以在这方面帮助我吗?

4

1 回答 1

1

尝试这个:

SELECT
    CASE 
    WHEN [status] = 1 THEN
        'unoccupied'
    WHEN [status] = 0 THEN
        'occupied'
    ELSE
        'All'
    END,
    *
FROM Tb_patientBeds
于 2012-12-04T06:19:13.133 回答