Evaluate 1 or NULL or Both in Stored Procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • totalsqlnewbie
    New Member
    • May 2013
    • 1

    Evaluate 1 or NULL or Both in Stored Procedure

    Hello,
    I have a field in a table that is either 1 or NULL. I have a stored procedure that evaluates this condition. I also have an SSRS (2008) report that passes a parameter to this stored procedure.

    If a user selects yes (passes 1) OR no (passes NULL), the following statement works correctly:

    Select *
    from foo
    where ISNULL(c1, 0) = ISNULL(@c1,0)

    However, I want the user to be able to select Yes, No, or BOTH, but I cannot figure out how to have the c1 field be either 1 or NULL to return ALL records. Any help would be greatly appreciated.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Use an OR to check for your BOTH value, whatever that is that you assigned to it.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      What do you mean by "both" ? A column can only hold a single value. It's either 1 or NULL.

      But if you mean that if a user wants to return everything regardless of it's value, you might need a conditional where clause.

      Good Luck!!!


      ~~ CK

      Comment

      Working...