Multiple condition in one IF expression

I want to add several conditions to one IF statement in SQL.

I am poorly versed in SQL and referring to some example, all show only one condition in IF.

Here is my procedure.

CREATE PROCEDURE [dbo].[AddApplicationUser]    
(  
@TenantId BIGINT,  
@UserType TINYINT,
@UserName  NVARCHAR(100),  
@Password NVARCHAR(100)  
)  

AS    

BEGIN   

IF ((@TenantId IS NULL)  AND (@UserType=0 OR @UserType=1) )
  RAISERROR('The value for @TenantID should not be null', 15, 1) -- with log 

Is this the correct syntax in SQL for multicomponent in IF?

+5
source share
2 answers

Yes, this is a valid syntax, but it may not do what you need.

Execution will continue after yours RAISERROR, unless you have added RETURN. Therefore, you will need to add a block c BEGIN ... ENDto store two statements.

Also, I'm not sure why you are facing seriousness 15. Which usually indicates a syntax error .

, , IN

CREATE PROCEDURE [dbo].[AddApplicationUser] (@TenantId BIGINT,
                                            @UserType TINYINT,
                                            @UserName NVARCHAR(100),
                                            @Password NVARCHAR(100))
AS
  BEGIN
      IF ( @TenantId IS NULL
           AND @UserType IN ( 0, 1 ) )
        BEGIN
            RAISERROR('The value for @TenantID should not be null',15,1);

            RETURN;
        END
  END 
+3

, , IF. . , . GL!

-1

All Articles