none
Using the IN operator in parentheses. Can it be done?

    Question

  • Hi, I'm new to SQL and query syntax, and am wondering why this syntax won't work:

    doesn't work

    SELECT SalesOrderID, TotalDue, TerritoryID, SalesPersonID  
    FROM Sales.SalesOrderHeader 
    WHERE TotalDue >= '1000' AND (SalesPersonID = 279 OR TerritoryID IN (6,4);

    works

    SELECT SalesOrderID, TotalDue, TerritoryID, SalesPersonID  
    FROM Sales.SalesOrderHeader 
    WHERE TotalDue >= '1000' AND (SalesPersonID = 279 OR TerritoryID = 6 OR TerritoryID = 4);

    can you not use the IN operator in parenthesis like this, or did I do it wrong?

    Sunday, August 04, 2013 12:57 AM

Answers

  • SELECT SalesOrderID, TotalDue, TerritoryID, SalesPersonID  
    FROM Sales.SalesOrderHeader 
    WHERE TotalDue >= '1000' AND (SalesPersonID = 279 OR TerritoryID IN (6,4);

    You as simply missing a close parenthesis.  Try:

     WHERE TotalDue >= '1000' AND (SalesPersonID = 279 OR TerritoryID IN (6,4));


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Sunday, August 04, 2013 1:19 AM

All replies

  • SELECT SalesOrderID, TotalDue, TerritoryID, SalesPersonID  
    FROM Sales.SalesOrderHeader 
    WHERE TotalDue >= '1000' AND (SalesPersonID = 279 OR TerritoryID IN (6,4);

    You as simply missing a close parenthesis.  Try:

     WHERE TotalDue >= '1000' AND (SalesPersonID = 279 OR TerritoryID IN (6,4));


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Sunday, August 04, 2013 1:19 AM
  • yep, that's what did it! Just an attention-to-detail error! thanks!!

    Thomas Gill

    Sunday, August 04, 2013 1:31 AM