SQL SELECT - Return boolean based on condition

后端 未结 5 1054
难免孤独
难免孤独 2020-12-30 23:10

Essentially I\'m trying to do this

select  u.Hostname, u.IsCustom, (u.Status = 5) as IsActive
from    SiteUrlMappings u

Where 5 is an int r

5条回答
  •  离开以前
    2020-12-30 23:23

    You need a case statement, like this:

    select  u.Hostname,
            u.IsCustom,
            convert(bit, case when u.Status = 5 then 1 else 0 end) as IsActive
    
    from    SiteUrlMappings u
    

    bit is as close to true boolean as you can get in SQL Server

提交回复
热议问题