| title | WHERE (Transact-SQL) | Microsoft Docs | |||||
|---|---|---|---|---|---|---|
| ms.custom | ||||||
| ms.date | 08/09/2017 | |||||
| ms.prod | sql-non-specified | |||||
| ms.reviewer | ||||||
| ms.suite | ||||||
| ms.technology |
|
|||||
| ms.tgt_pltfrm | ||||||
| ms.topic | language-reference | |||||
| f1_keywords |
|
|||||
| dev_langs |
|
|||||
| helpviewer_keywords |
|
|||||
| ms.assetid | a8430421-7bce-4fab-a2d2-56c00a3c6fa4 | |||||
| caps.latest.revision | 37 | |||||
| author | BYHAM | |||||
| ms.author | rickbyh | |||||
| manager | jhubbard |
[!INCLUDEtsql-appliesto-ss2008-all_md]
Specifies the search condition for the rows returned by the query.
Transact-SQL Syntax Conventions
-- Syntax for SQL Server, Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse
[ WHERE <search_condition> ]
< search_condition > Defines the condition to be met for the rows to be returned. There is no limit to the number of predicates that can be included in a search condition. For more information about search conditions and predicates, see Search Condition (Transact-SQL).
The following examples show how to use some common search conditions in the WHERE clause.
USE AdventureWorks2012
GO
SELECT ProductID, Name
FROM Production.Product
WHERE Name = 'Blade' ;
GO
SELECT ProductID, Name, Color
FROM Production.Product
WHERE Name LIKE ('%Frame%');
GO
SELECT ProductID, Name
FROM Production.Product
WHERE ProductID <= 12 ;
GO
SELECT ProductID, Name
FROM Production.Product
WHERE ProductID = 2
OR ProductID = 4
OR Name = 'Spokes' ;
GO
SELECT ProductID, Name, Color
FROM Production.Product
WHERE Name LIKE ('%Frame%')
AND Name LIKE ('HL%')
AND Color = 'Red' ;
GO
SELECT ProductID, Name, Color
FROM Production.Product
WHERE Name IN ('Blade', 'Crown Race', 'Spokes');
GO
SELECT ProductID, Name, Color
FROM Production.Product
WHERE ProductID BETWEEN 725 AND 734;
GO
The following examples show how to use some common search conditions in the WHERE clause.
-- Uses AdventureWorks
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE LastName = 'Smith' ;
-- Uses AdventureWorks
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE LastName LIKE ('%Smi%');
-- Uses AdventureWorks
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE EmployeeKey <= 500;
-- Uses AdventureWorks
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE EmployeeKey = 1 OR EmployeeKey = 8 OR EmployeeKey = 12;
-- Uses AdventureWorks
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE EmployeeKey <= 500 AND LastName LIKE '%Smi%' AND FirstName LIKE '%A%';
-- Uses AdventureWorks
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE LastName IN ('Smith', 'Godfrey', 'Johnson');
-- Uses AdventureWorks
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE EmployeeKey Between 100 AND 200;
DELETE (Transact-SQL)
Predicates (Transact-SQL)
Search Condition (Transact-SQL)
SELECT (Transact-SQL)
UPDATE (Transact-SQL)
MERGE (Transact-SQL)