Solved

Simple IF...Else Statement to convert 1/0 to Yes/No

Posted on 2008-06-25
4
368 Views
Last Modified: 2011-10-03
I am new to T-SQL and am using reporting services to create reports from the database. However, the database shows a field called Active as 1 or 0. I want it to say Yes if 1 is shown and No if 0 is shown. I dont want to update the database to Yes or No but keep that 1/0 although when i want to report that field, i want to show Yes/no

This is my query as of now.

IF ( SELECT active from dbo.user where active ='1') = '1'
BEGIN
PRINT 'YES'
Select active from dbo.user where active = '1'
END
ELSE
IF (Select active from dbo.user where active ='0') ='0'
BEGIN
PRINT 'NO'
END

The Error says - MSG 512 Subquery returned more than 1 value. This is not permitted when the subquery follows =,!=,... or when the subquery is used as an expression.

I am sorry as i am new to this and probably have it all wrong. Please advice it will be greatly appreciated.
0
Comment
Question by:nsehmi
4 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21867907
IF exists( SELECT active from dbo.user where active ='1')
BEGIN
PRINT 'YES'
Select active from dbo.user where active = '1'
END
ELSE
IF exists(Select active from dbo.user where active ='0')
BEGIN
PRINT 'NO'
END
0
 
LVL 2

Accepted Solution

by:
pierky earned 50 total points
ID: 21867909
Try this...
SELECT

   CASE active

      WHEN 1 THEN 'Yes'

      ELSE 'No'

   END AS active

FROM

   user

Open in new window

0
 
LVL 7

Expert Comment

by:60MXG
ID: 21867965
Try to change '=' to 'is'
0
 

Author Closing Comment

by:nsehmi
ID: 31470671
Thanks so much. It was so much easier then expected!
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now