Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7174693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:06:40+00:00 2026-05-28T16:06:40+00:00

I have a stored proc I am trying to write , where I want

  • 0

I have a stored proc I am trying to write , where I want to evaluate multiple conditions on the different parameters in one go. What is the best syntax for this?

Below is what I have:

AS
BEGIN
    DECLARE @GARRISON nvarchar(255)
    DECLARE @ASSETTYPE nvarchar(255)
    DECLARE @FIVALUE int

    IF (  ( @GARRISON IS NOT 'Netheravon' 
            AND @GARRISON IS NOT 'Ludgershall'
          )
          AND @INTERRUPT >= 5)
        BEGIN

        END
    ELSE

END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:06:41+00:00Added an answer on May 28, 2026 at 4:06 pm

    You can use.

    IF ((@GARRISON != 'Netheravon' AND @GARRISON != 'Ludgershall') )
    AND @INTERRUPT >= 5)
    

    This can be shortened to

    IF (@GARRISON NOT IN ('Netheravon', 'Ludgershall' )
    AND @INTERRUPT >= 5)
    

    The problem you had was that you have @variable IS NOT 'constant' – this isnt valid SQL Syntax unless checking for null. For equality use =, for non-equality use != or <> (Both work IIRC).


    Edit: This is the exact sctipt I used for testing, and works exactly as expected. SQL Server 2008

    DECLARE @GARRISON nvarchar(255)
    DECLARE @INTERRUPT INT
    
    SET @GARRISON = 'Test'
    SET @INTERRUPT = 10
    
    
    IF (@GARRISON NOT IN ('Netheravon' ,'Ludgershall' )
       AND @INTERRUPT >= 5)  
    BEGIN
    SELECT 1
    END
    

    The above correctly outputs “1” as both conditions evaluate true. If I either change @INTERRUPT to 4, or @GARRISON to either Netheravon or Ludgershall then there is no output. This is the exact behaviour I expect.

    Note: You can’t have an empty BEGIN...END block in SQL, so if that is empty you’ll get the error Incorrect syntax near 'END'.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored proc that I am passing two parameters into. One parameter
I have a stored proc in sql-server and one of the parameters it returns
I have a Stored proc which returns 6 select statement results. I'm trying to
I have a stored proc, SP1, which executes and does select on one table.
If I have this stored proc definition minus the body ALTER PROCEDURE sp_AlloctionReport(@where NVARCHAR(1000),
I'm trying to do something like this in My MySQL stored proc: if val
I have a dataset being returned by a stored proc and one of the
I am trying to write a simple stored proc which takes three arguments 'database
I have a stored proc, say, call_Me with few parameters: Declare @Greet varchar(100) =
I have a stored proc on sql server 2008 that excepts a int parameter.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.