Convert bit type to Yes or No by query Sql Server 2005

后端 未结 5 913
一整个雨季
一整个雨季 2021-01-07 17:48

I Want convert bit type to Yes or No

For Example:

SELECT FirstName, LastName, IsMale from members
         


        
5条回答
  •  执笔经年
    2021-01-07 17:57

    SQL Server 2012 introduces two new keywords FORMAT and IIF that can provide a more compact means of converting an integer or bit to string:

    DECLARE @MyInt int = 123
    PRINT 'Hello '+FORMAT(@MyInt,'')
    
    -- (note: the "+0" converts a bit type to int then outputs '0' or '1')
    DECLARE @MyBit bit = 0
    PRINT 'Hello '+FORMAT(@MyBit+0,'')
    

    But to convert a bit type to Yes or No I would now use:

    PRINT 'Hello '+IIF(@MyBit=1,'Yes','No')
    

提交回复
热议问题