473,549 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Return Boolean TRUE/FALSE Values

NeoPa
32,564 Recognized Expert Moderator MVP
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 57772
romiverma
11 New Member
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,564 Recognized Expert Moderator MVP
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 Recognized Expert Moderator Expert
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,564 Recognized Expert Moderator MVP
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 Recognized Expert Moderator Expert
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,564 Recognized Expert Moderator MVP
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 Recognized Expert Specialist
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,564 Recognized Expert Moderator MVP
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
4768
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 variable $noFile, it is print "1" instead of "true". Why does it do this? The loop is failing to run a second time, for reasons I can not fathom....
35
3349
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
2448
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 "counted" string and data in a binary file. Given... #include <stdio.h> int main(int argc, char *argv) { char bstring;
59
4551
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 So I changed my test for the obvious "if type(v) is bool", but I still find it confusing that "0 in " returns True
4
1450
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 in my database. This (obviously) leads to all 'False' fields being disabled and 'True' ones being enabled. What expression can I used instead...
71
33146
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 (TRUE) #define TRUE (1)
40
2698
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 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) on win32 Type "help", "copyright", "credits" or "license" for more
14
3861
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
7726
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7967
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7485
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.