Tuesday, January 16, 2018

How To Use Between Operator In Mssql

Hello Friend Today In This Blog I Will Show You How To Use Between Operator In Mssql.The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.The SQL BETWEEN condition allows you to easily test if an expression is within a range of values (inclusive). It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.This SQL tutorial explains how to use the SQL BETWEEN condition with syntax and examples.The operator BETWEEN and AND, are used to compare data for a range of values. In this tutorial, you will learn how to use SQL BETWEEN operator to select data within a range of values.The BETWEEN operator is used in the WHERE clause to select a value within a range of values. We often use the BETWEEN operator in the WHERE clause of the SELECT, UPDATE and DELETEstatements.The BETWEEN operator returns TRUE if the result of the expression or value of the column specified in the WHERE clause is less than or equal to lower_value and greater than or equal to upper_value. Otherwise, it returns FALSE. The BETWEEN operator is inclusive.To specify an exclusive range, you use the less than (<) and greater than (>) operators instead.If you pass the NULL values to the BETWEEN operator e.g., expr,  lower_value or upper_value, the BETWEEN operator returns NULL.You can combine the BETWEEN operator with the NOT operator to find rows whose column values are not in a range of values.If you observe above SQL BETWEEN operator syntax we are getting values where column1 value between value1 and value2.Generally in SQL statement if we use BETWEEN operator it will return record where value between within range. Suppose if we use NOT keyword with BETWEEN operator it will return data where column value not in between range of values.Generally in SQL statement if we use BETWEEN operator with character values it will return all the records where the column name beginning with any letter between character string values. Suppose if we use NOT with BETWEEN operator it will return all records where column name not start between string values.


BETWEEN Syntax

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;


Here Is An Example Related To Topic

Step 1 :Create database

Create database Onlineshopping_db



Step 2:Create table

Here In This step We Will Create table.

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

create table Customer_table_news
(
Cids bigint,
Cname varchar(50),
Ccountry 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 Customer_table_news values(1,'VIRAJ','INDIA',15000.00)
Insert Into Customer_table_news values(2,'RAJ','USA',10000.00)
Insert Into Customer_table_news values(3,'ANIL','UK',12000.00)
Insert Into Customer_table_news values(4,'SUNIL','CANEDA',9000.00)
Insert Into Customer_table_news values(5,'SHERYAS','CHINA',11000.00)
Insert Into Customer_table_news values(6,'AJAY','CHINA',16000.00)

select *from Customer_table_news




Step 4 :Create Between Operator  

Here In This Step We Will Use Between Operator Using Where Clause By Using Between Operator.
Data Will Be Added Manually Using Between Operator.

Here  Data Is Found By Between Operator By Passing CPrice BETWEEN 9000.00 AND 15000.00

SELECT * FROM Customer_table_news

WHERE CPrice BETWEEN 9000.00 AND 15000.00;




Here  Data Is Found By Between Operator By Passing CPrice NOT BETWEEN 9000.00 AND 15000.00

SELECT * FROM Customer_table_news

WHERE CPrice NOT BETWEEN 9000.00 AND 15000.00;




Here Is Video Related To Topic Below


No comments:

Post a Comment