0

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

1 Answer 1

2

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

IF @CORP IN ('something', 'somethingElse')
BEGIN
    -- your code
END
Sign up to request clarification or add additional context in comments.

3 Comments

oh, i thought this only works on where clause. Thanks!
I'm new to most of sql, and would love to know what the '@' character is used for. Is it like the $ variable in php to create a variable (hence making @CORP a variable in SQL) or is it something completely different?
@Webeng Yes, it is variable, and in SQL Server variables first character must be @. See technet.microsoft.com/en-us/library/ms187953(v=sql.105).aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.