?
Solved

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

Posted on 2003-12-02
2
Medium Priority
?
746 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

770 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