We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Converting a Bit field to varchar True/False

Medium Priority
6,804 Views
Last Modified: 2012-05-06
Hello Experts,

I'm using convert(varchar(50), @LetterReceived) to convert a bit to varchar, but it only returns 1 or 0.  I need it to return True or False.  Is there a convert or cast like function that does this?  Environment is SQL Server 2005

Thanks
Comment
Watch Question

Commented:
that is not the way you write the query..if you want to see true or false...

SELECT CASE WHEN @LetterRecieved = 1 THEN 'True'
              ELSE 'False' END
FROM YourTable
James MurrellQA Product Specialist
CERTIFIED EXPERT

Commented:
why not use a "case" if 1 ='true' etc

Author

Commented:
I've got the code below with different fields many times in my sproc.

if (Select [LetterReceived] from #temp1) <> @LetterReceived       
          Set @summary = 'LetterReived updated to' + convert(varchar(50), @LetterReceived)

Commented:
I dont understand what is your question. Can you be more clear with a little more explanation.

Author

Commented:
@LetterReceived is a bit parameter so it returns 1 or 0.  I'm using it in a string for users so I'd like it to return true or false.  I'd like to use an existing function like conver or cast.  Do you know if one, a function that will convert a bit to True or False.

Commented:
Try this

if (Select [LetterReceived] from #temp1) <> @LetterReceived      
          Set @summary = 'LetterReived updated to ' + convert(varchar(50), CASE WHEN @LetterRecieved = 1 THEN 'True' ELSE 'False' END )
Senior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
SUBSTRING('FalseTrue', @LetterReceived * 5 + 1, 5)

Or:

    Set @summary = 'LetterReived updated to' + substring('FalseTrue', @LetterReceived * 5 + 1, 5)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks for all your help.

scott that's way cool.  I've got a couple of places where I can use that concept.
Scott PletcherSenior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
Yep ... an old BASIC trick that still comes in handy :- ) .
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.