return yes/no rather than true/false

  • I have a bit column and I'm creating a report and its returning True or False based on 0 or 1 in the column. How do I convert True/False to Yes/No in my query to display in the report?

  • You can use a case statement.

    Declare @TST1 bit

    Declare @tst2 bit

    Set @TST1 = 1

    Set @tst2 = 0

    Select Case @TST1 When 1 Then 'Yes' Else 'No' END ,

    Case @tst2 When 1 Then 'Yes' Else 'No' END

  • thanks Ken that worked for me!

  • Keep in mind that I am counting a NULL value as No also.

  • hmmm how would I handle a NULL values?

  • You just add in the extra handler:

    Select Case @TST1 When 1 Then 'Yes' Else 'No' END ,

    Case @tst2 When 1 Then 'Yes' Else 'No' END

    Changes to:

    [font="Courier New"]SELECT CASE @tst1    WHEN 1 THEN 'Yes'

               WHEN 0 THEN 'No'

               ELSE 'Unknown'

               END,

           CASE @tst2  WHEN 1 THEN 'Yes'

               WHEN 0 THEN 'No'

               ELSE 'Unknown'

               END

    [/font]

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply