Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Analternate values for Boolean datatypes

Author  Topic 

scvinod
Starting Member

16 Posts

Posted - 2009-08-03 : 08:51:52
Hi All,

Is it possible to have have our own values instead of true/false for a column that is of type Boolean.I very much need to have my own values.Please help me out.Thanks in advance.

scv

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-03 : 08:55:37
There is no BOOLEAN in SQL Server. There is BIT column which can have 1 (True) or 0 (False).
You can use CHAR(1) NOT NULL to have your own "True/False" values but coding for that will be somewhat harder.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

johnconstraint
Starting Member

23 Posts

Posted - 2009-08-03 : 09:08:34
You can use the BIT column with 1 and 0 as the valid values and map 1 to your application's first value and 0 to the second.
Go to Top of Page

scvinod
Starting Member

16 Posts

Posted - 2009-08-03 : 09:09:20
Hey can u please elaborate more on that.

scv
Go to Top of Page

johnconstraint
Starting Member

23 Posts

Posted - 2009-08-03 : 11:50:57
I had a similar situation with one of my projects. My front end application had two radio buttons which are mutually exclusive. I mapped the first button to "True" and the second to "False". It made sense for my project, not sure if this would work for you.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-08-03 : 13:08:46
bit can be, 1, 0, or null

What are your own values that you need?

Can't you just use char(1)?




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

scvinod
Starting Member

16 Posts

Posted - 2009-08-03 : 13:39:55
Hey all thanks for the replies.I will post my question clearly right now.

I have a ASP.Net web application which has a gridview.The Gridview has a CheckBoxField coumn which has to be populated with a Boolean or a Bit type column from the table in the database.Now the problem is the CheckBoxes in the CheckBoxField column must be checked if the corresponding value in the Table is 'X' and unchecked if the corresponding value in the Table is 'Y'.It must check for X and Y instead of 0 and 1.Pls help me out.Thanks in advance.

scv
Go to Top of Page

johnconstraint
Starting Member

23 Posts

Posted - 2009-08-03 : 14:14:10
You can define the column in the table as BIT and when you develop the Gridview it should automatically display a checkbox in the grid. When user checks the checkbox a value of "true" will be stored in the BIT column. The otherway also holds good, for a "true" value of the BIT column, the checkbox in the gridview will be shown as checked.
Go to Top of Page
   

- Advertisement -