Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Convert 1/0 (bit) into True/False or Yes/No within query?

Posted on 2003-12-02
2
Medium Priority
?
748 Views
Last Modified: 2010-08-05
Hi everyone-

Is there a way to convert the output of a bit (0/1) into True/False or Yes/No within a query?

I am calling a stored procedure that sends an email (with query results), and I just relized that one of the fields is a Bit, so it comes out 1 or 0.

I would like it to return something easier for a "common user" to understand, like True/False, or Yes/No.


*********************************
(Inventory..Inventory.discontinued is set to type Bit)

CREATE PROCEDURE [dbo].[sp_reorderInventorySendMail]
...
...
...
set @sqlQuery = "SELECT 'Discontinued?: ', Inventory..Inventory.discontinued FROM Inventory..Inventory WHERE Inventory..Inventory.id = " + convert(varchar(5), @itemId)

EXEC master..xp_sendmail
      @recipients = @inventoryManagerEmail,
      @copy_recipients = '',
      @subject = 'Inventory: Inventory Reorder Requested',
      @message = 'Inventory detected an item below inventory level.  The following information was returned:',
      @query = @sqlQuery,
      @no_header = true
GO
*********************************
0
Comment
Question by:pillbug22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
adwiseman earned 400 total points
ID: 9861018
Use a case statement

Select CASE <field> WHEN 0 then 'False' ELSE 'True' END as Myfield

set @sqlQuery = "SELECT 'Discontinued?: ', CASE Inventory..Inventory.discontinued WHEN 0 then 'False' ELSE 'True' END as discontinued FROM Inventory..Inventory WHERE Inventory..Inventory.id = " + convert(varchar(5), @itemId)
0
 
LVL 6

Author Comment

by:pillbug22
ID: 9861081
Ah...that'll do it - thanks!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

604 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