Wednesday, January 17, 2018

How To Use AND,OR and NOT Operator In Mssql

Hello Friend Today In This Blog I Will Show You How To Use AND,OR and NOT Operator In Mssql.The WHERE clause can be combined with AND, OR, and NOT operators.You can specify multiple conditions in a single WHERE clause to, say, retrieve rows based on the values in multiple columns. You can use the AND and OR operators to combine two or more conditions into a compound condition. AND, OR, and a third operator, NOT, are logical operators. Logical operators, or Boolean operators, are operators designed to work with truth values: true, false, and unknown.The AND and OR operators are used to filter records based on more than one condition:
1)The AND operator displays a record if all the conditions separated by AND is TRUE.

2)The OR operator displays a record if any of the conditions separated by OR is TRUE.

The NOT operator displays a record if the condition(s) is NOT TRUE.

There are three Logical Operators namely, AND, OR, and NOT. These operators compare two conditions at a time to determine whether a row can be selected for the output. When retrieving data using a SELECT statement, you can use logical operators in the WHERE clause, which allows you to combine more than one condition.If you want to select rows that satisfy at least one of the given conditions, you can use the logical operator, OR.If you want to select rows that must satisfy all the given conditions, you can use the logical operator, AND.If you want to find rows that do not satisfy a condition, you can use the logical operator, NOT. NOT results in the reverse of a condition. That is, if a condition is satisfied, then the row is not returned.The Logical operators are those that are true or false. They return a true or false values to combine one or more true or false values.SQL gets complex when you have multiple business rules that run how you return record sets. As a coder, you gather business rules that then decide how to structure your SQL statements to ensure that returned results are accurate for reports and applications. These statements get complex when you have several business requirements that must be used to return a data set that helps businesses make decisions. Some SQL keywords that help you build complex statements include IN, NOT, and LIKE. LIKE uses wildcards, which are used to query similar values, but IN and NOT return precise record sets based on specific values. 

AND Syntax

SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

OR Syntax

SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;

NOT Syntax

SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;


Here Is An Example Related To Topic


Step 1 :Create database

Create database BMC



Step 2:Create table

Here In This step We Will Create table.


Here In This Step We Required Four Column With Name Cids ,Cname ,Ccity And CPrice using Parameter bigint,varchar and float.

create table Client_table_news
(
Cids bigint,
Cname varchar(50),
Ccity varchar(200),
CPrice float
);




Step 3 :Create Insert Trigger Functionality

Here In This Step We Will Insert Data Using Insert Command.
Data Will Be Added Manually Using Insert Command.


Insert Into Client_table_news values(1,'VIRAJ','MUMBAI',15000.00)
Insert Into Client_table_news values(2,'RAJ','DELHI',10000.00)
Insert Into Client_table_news values(3,'ANIL','PUNE',12000.00)
Insert Into Client_table_news values(4,'SUNIL','MUMBAI',9000.00)
Insert Into Client_table_news values(5,'SHERYAS','JAIPUR',11000.00)
Insert Into Client_table_news values(6,'AJAY','MUMBAI',16000.00)

select *from Client_table_news


Step 4 :Create AND,OR and NOT Operator

Here In This Step We Will Create AND,OR and NOT Operator Using Where Clause.
Using Different Example We Will Show You The Application Of AND,OR and NOT Operator In This Blog.

AND Operator:


SELECT * FROM Client_table_news

WHERE Cname ='VIRAJ' AND Ccity ='MUMBAI';


OR Operator:


SELECT * FROM Client_table_news
WHERE Ccity='PUNE' OR Ccity='MUMBAI';




NOT 
Operator:


SELECT * FROM Client_table_news
WHERE NOT Ccity='MUMBAI';


Here Is An Video Related To Topic In This blog Below,You Will Clear All The doubt Related To Topic Above.This Two Video Will Be Helpful To You,To Understand The Topic In This Blog.

1 comment: