Tuesday, May 13, 2014

TSQL (Transact-SQL) Tutorial: AND Operator


In TSQL AND Operator is used to check for two or more conditions in a SELECT, INSERT, UPDATE, or DELETE statement.

The syntax for the AND Operator in TSQL is:

WHERE condition1
AND condition2
...
AND condition_n;

If you want to implement multiple condition in a TSQL Query and requirement is to apply all those conditions simultaneously then you use AND operator.

Using with SELECT Statement

Let say i want all employees whose surname is chopra and their salary is greater than 10000. Then to get result we need to apply both the condition. To implement this we can use and operator between two condition in where clause.

For example:

SELECT *
FROM employees
WHERE last_name = 'Chopra'
AND Salary < 10000;

This way the above query will return the result sets which are required.  

Same way you can use it for joining the table with multiple condition. Delete, insert or update row from base table using multiple conditions.

No comments:

Post a Comment