Swap a "1" or "0" for a "Y" or "N"


I have a sql query that returns rows of data and one field returns a 1 (which means yes) or a 0 (which means no).  On my vb.net page, how do I replace the 1 with a Yes and the 0 with a No?  Or do I do this in the sql?  How do I do this in sql?

Never make important decisions on a Monday!
0
funluckykitty
9/3/2008 5:47:26 PM
📁 asp.net.sql-datasource
📃 29906 articles.
⭐ 0 followers.

💬 5 Replies
👁️‍🗨️ 1402 Views



By default, VB.Net can understand 1 as Yes and 0 as No.
I believe you are using those DB values for your Boolean Operations.
Try to use If <DBValue> then <Operation>.
 If you are really need Yes/No .... Declare boolean variable in VB.net and set those variables.
 

Thanks and Regards,
Venu B Pavuluri
0
venu_babu80
9/3/2008 5:51:51 PM

SELECT column1, column2,
CASE YourColumnForYorN
WHEN '1' THEN 'Y'
WHEN '0' THEN 'N'
ELSE 'Error'
END
FROM TableName


Hope it helps.

-Manas

=======================================
If this post is useful to you, please mark it as answer.
0
yeotumitsu
9/3/2008 5:52:06 PM

You can do this either on your page or from SQL by using a CASE statement.
SELECT CASE WHEN col1=1 THEN 'YES' ELSE 'NO' END as col1 FROM yourTable

Limno

0
limno
9/3/2008 5:54:49 PM

What datatype your using for the 1/0/Y/N ? i assume CHAR(1) ?
Why dont you use BIT ? which is 0 and 1 - True or False
I use BIT for all my checkboxes in asp.net and c#
dr2 = datareader
thw_Enabled = SQL Column with BIT as datatype
cbEnabled = Checkbox in asp.net c# front end
cbEnabled.Checked = Convert.ToBoolean(dr2["thw_Enabled"].ToString());
0
fossil1983
9/3/2008 5:59:03 PM

if you need to do it in the VB code, you can use String.Format like this:
String.Format("{0:yes;yes;no}", myValue)
Assuming that myValue is a numeric, it will display "yes" for any non-zero value, and "no" for any zero values. Replace yes and no in that format string as you need.
0
shados
9/3/2008 6:03:26 PM
Reply: