473,418 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

How to Return Boolean TRUE/FALSE Values

NeoPa
32,556 Expert Mod 16PB
I am trying, with a spectacular lack of success, to return TRUE and FALSE values in my SELECT statement. This SQL (below) is simply illustrative. It doesn't reflect my real world query. I would just like to know how to return such values in T-SQL.
Expand|Select|Wrap|Line Numbers
  1. SELECT [PR_PRODUCT]
  2.       ,TRUE AS [CostMissing]
  3.  
  4. FROM   [DBManagement].[dbo].[vwCustStock]
  5.  
  6. WHERE  ([PR_RANGE] In(70,91))
  7.  
  8. GO
  9.  
  10. Msg 207, Level 16, State 1, Line 2
  11. Invalid column name 'TRUE'.
For an idea, should anyone want it, why I need this please see SELECT Assertion.
Jun 30 '10 #1
8 57724
hi neopa!
Try this
Expand|Select|Wrap|Line Numbers
  1. SELECT [PR_PRODUCT]
  2.       ,'TRUE' AS [CostMissing]
  3.  
  4. FROM   [DBManagement].[dbo].[vwCustStock]
  5.  
  6. WHERE  ([PR_RANGE] In(70,91))
use single quotes for true as its not an integer value
Jun 30 '10 #2
NeoPa
32,556 Expert Mod 16PB
Thanks for your suggestion. However, adding the quotes forces the value to be a string, which is not what I'm after. I've renamed the thread to make this point clearer. I'm after returning Boolean values explicitly. I know how to return them as the result of a function call, and various other ways, but I'd like to know how to return a specific boolean value.

I do appreciate your attempting to help anyway :)
Jun 30 '10 #3
Banfa
9,065 Expert Mod 8TB
Since Transact-SQL has no boolean data type (see Data Types (Transact-SQL)) it is reasonable that it doesn't support constant values of that type (i.e. true and false).

I suggest you return 0 (false) and 1 (true).
Jun 30 '10 #4
NeoPa
32,556 Expert Mod 16PB
Thanks Banfa.

There's some sense in that, but as it seems to support the Bit datatype, which mentions values of True and False, as well as undefined, would it not be reasonable to expect explicit values of True and False to be available? It makes reading the SQL and making sense of it so much easier after all. I know you have no power to change how it's set up, but I'd be interested to read your thinking in response to this point.
Jun 30 '10 #5
Banfa
9,065 Expert Mod 8TB
Actually that page says

An integer data type that can take a value of 1, 0, or NULL.
It doesn't say it can take the values true and false but rather that strings with the value 'TRUE' and 'FALSE' can be converted to a bit field. I believe this will happen implicitly in the right context but otherwise an explicit cast/convert is required.

The contexts I have seen in your threads are not ones where the field is already of type bit and therefore you would need to explicitly cast/convert something like

cast('TRUE' as bit)

I think. I can't test this as I don't currently have an SQL Server installed.
Jun 30 '10 #6
NeoPa
32,556 Expert Mod 16PB
Thanks Banfa. I must admit that their use of TRUE and FALSE favlues, rather than 'TRUE' and 'FALSE' as you have it and I would expect from string values, threw me right off the scent. Notwithstanding their reference to String values of ....

It would seem then, strangely in my view, that SQL Server doesn't support the concept of predefined values for TRUE and FALSE. Thanks for helping to get there in the end.
Jun 30 '10 #7
ck9663
2,878 Expert 2GB
This cast('TRUE' as bit) will work.

Actually when you view the table using Enterprise Manager (Open Table), bit data type columns will show True/False, not 1/0. Editing the value, though, still requires you input 1 or 0.

Happy Coding!!!

~~ CK`
Jun 30 '10 #8
NeoPa
32,556 Expert Mod 16PB
Thanks CK. At least I now think I know where I stand with all this :)
Jun 30 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: lawrence | last post by:
In the following loop, at the end, the method debugNotes() is printing out some notes for me to read, so I can figure out what is going on in my script. Where I try to print out the value of the...
35
by: Steven Bethard | last post by:
I have lists containing values that are all either True, False or None, e.g.: etc. For a given list: * If all values are None, the function should return None.
14
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a...
59
by: Pierre Quentel | last post by:
Hi all, In some program I was testing if a variable was a boolean, with this test : if v in My script didn't work in some cases and I eventually found that for v = 0 the test returned True ...
4
by: Steve | last post by:
As you know there is a databindings property 'Enabled' for fields in the gridview. In the custom binding section I have used the expression: Eval("myfield"). 'myfield' is a boolean field I have...
71
by: David T. Ashley | last post by:
Where is the best place to define TRUE and FALSE? Are they in any of the standard include files, ever? Do any standards apply? What I've traditionally done is something like: #ifndef...
40
by: nufuhsus | last post by:
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python...
14
by: donbock | last post by:
A side-discussion developed in the Wierd Visual Studio Problem thread. Rather than continue to hijack that topic, I've created a new thread and copied over the relevant postings.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.