Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Converting a Bit field to varchar True/False

Posted on 2009-02-12
9
Medium Priority
?
6,281 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
0
Comment
Question by:eshurak
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 8

Expert Comment

by:k_rasuri
ID: 23628075
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
0
 
LVL 31

Expert Comment

by:James Murrell
ID: 23628078
why not use a "case" if 1 ='true' etc
0
 
LVL 3

Author Comment

by:eshurak
ID: 23628098
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)
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 8

Expert Comment

by:k_rasuri
ID: 23628105
I dont understand what is your question. Can you be more clear with a little more explanation.
0
 
LVL 3

Author Comment

by:eshurak
ID: 23628122
@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.
0
 
LVL 8

Expert Comment

by:k_rasuri
ID: 23628219
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 )
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 23628292
SUBSTRING('FalseTrue', @LetterReceived * 5 + 1, 5)

Or:

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

Author Comment

by:eshurak
ID: 23628586
Thanks for all your help.

scott that's way cool.  I've got a couple of places where I can use that concept.
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 23632843
Yep ... an old BASIC trick that still comes in handy :- ) .
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question