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
 Boelean data type

Author  Topic 

SQLBoy14
Yak Posting Veteran

70 Posts

Posted - 2014-03-31 : 14:29:15
Hi all,

one of the parameter in my stored procedures is the Boelean data type. So, for now the user(s) can select two value whether false (0) or True (1) in the parameter option. Now, if I want to give another option to user(s) that they don't have to select neither false (0) or true (1), how do I do that?

I have declare my boelean parameter in my stored procedures as @Graduate


Thank you all

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-03-31 : 15:26:56
If the data type is BIT, the only other option you have is a NULL - which is essentially indicating that the value is unknown.
Go to Top of Page

SQLBoy14
Yak Posting Veteran

70 Posts

Posted - 2014-03-31 : 23:08:34
Hi James, the NULL return to my false value. Here is what I wrote:

Alter Proc Students
@Graduate

AS
Begin

SELECT StudentID, StudentName, Grad
FROM NationalStudent
WHERE Grad = (Select ISNULL(@Graduate, Grad)

So, I want to have an option if I leave the parameter to null then I will have a list StudentID, StudentName, and Graduation status "Yes" and "No" (Yes for 1) and (No for 0)

Right know, if I leave it null, it actually output the 0 or No instead both.

Thank you James








SQLBoy
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-04-01 : 08:41:46
That should return all records if @Graduate is null.
SELECT StudentID, StudentName, Grad
FROM NationalStudent
WHERE Grad = ISNULL(@Graduate, Grad)
Add a "Print @Graduate" before your select statement to see what is actually coming into the stored proc.
Go to Top of Page
   

- Advertisement -