Santanu Maulik
Santanu Maulik

Reputation: 111

How to get all rows for 2 different values from SQL Server with a single parameter?

This is a part of my stored procedure:

ALTER PROCEDURE [dbo].[GetStudentRegistrationDetails] 
        @TotalDataCount INT OUT,    
        @currentPage INT = 1,    
        @pageSize INT = 0,
        @Username  NVARCHAR(500) = NULL,
        @Userstatus INT = NULL,
        @Userregisteredby INT = NULL
    AS
    BEGIN
        SET NOCOUNT ON;

        SELECT 
                @TotalDataCount = COUNT (*) 
        FROM    VW_UserDetails  
        WHERE   RoleId=2
        AND     USERFULLNAME LIKE ISNULL(RTRIM(@UserName) + '%',USERFULLNAME)
        AND     CAST(ISNULL(Status,0) AS INT) = ISNULL(@Userstatus,Status)

        AND     CreatedBy = CASE    
                                    WHEN @Userregisteredby = 0 THEN 0
                                    ELSE CreatedBy
                            END

For Status my table has to values either 1 or NULL.

 AND     CAST(ISNULL(Status,0) AS INT) = ISNULL(@Userstatus,Status)

With this line of code, I am able to get values for 1 if I send 1 from my front end as parameter & for null I am able to get all null if I send 0 from my front end as parameter.

Actually I am sending 0 or 1 as parameter from RadioButtonList value fields. But I want to get also both NULL & 1 together also with a single parameter from from front end.

What should I send from front end or what correction do I need o get both ?

Guide me please.

Upvotes: 0

Views: 46

Answers (1)

Mikael Eriksson
Mikael Eriksson

Reputation: 139010

Set the parameter to 2 and use or @Userstatus = 2.

Upvotes: 1

Related Questions