Ad

Allow Stored Procedure To Accept The Values

- 1 answer

I new to SQL, and I need one parameter called @User1 in the stored procedure to accept just 3 words for example ('max', 'low', 'high'), otherwise it should be an error.

I try to type this but it doesn't work I mean it accept any string value of data and I need to just 3 words:

IF @User1 <> 'max' OR @User1 <> 'low' OR @User1 <> 'high'
BEGIN
    SET @ErrorNumber = 3
    RETURN 0 
END
Ad

Answer

You need an AND instead of an OR between your conditions. As from OP's last comment, to also make it case insensitive:

IF  LOWER(@User1) <> 'max' and LOWER(@User1) <> 'low' and LOWER(@User1) <>'high'
BEGIN 
    SET @ErrorNumber = 3
    RETURN 0 
END 

Or simply

IF  LOWER(@User1) NOT IN ('max', 'low', 'high')
BEGIN 
    SET @ErrorNumber = 3
    RETURN 0 
END 
Ad
source: stackoverflow.com
Ad