JC Borlagdan JC Borlagdan - 9 months ago 24
SQL Question

SQL Query IF Statement in Stored Procedure

What is the proper and efficient way of making the condition in the given query?

Yes it's working, but I want the query to be more efficient, example what if there's a lot of strings to be validated with @CORP.

ALTER PROCEDURE [dbo].[sp_EditProfile]
@CORP AS VARCHAR(100)
AS
BEGIN
IF((@CORP = 'something') OR (@CORP = 'somethingElse')) //CONDITION
BEGIN
END
END

Answer

You can use IN statement, that will save you some characters of typing:

IF @CORP IN ('something', 'somethingElse')
BEGIN
    -- your code
END