Tuesday, January 16, 2018

How To Use Like Operator In Mssql

Hello Friend Today In This Blog I Will Show You How To Use Like Operator In Mssql.The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.The SQL LIKE clause is used to compare a value to similar values using wildcard operators.The percent sign represents zero, one or multiple characters. The underscore represents a single number or character. These symbols can be used in combinations.WHERE LIKE determines if a character string matches a pattern.Use WHERE LIKE when only a fragment of a text value is known.WHERE LIKE supports two wildcard match options: % and _.

There are two wildcards used in conjunction with the LIKE operator:

1) % - The percent sign represents zero, one, or multiple characters

2) _ - The underscore represents a single character

This SQL tutorial explains how to use the SQL LIKE condition (to perform pattern matching) with syntax, examples, and practice exercises.The SQL LIKE condition allows you to use wildcards to perform pattern matching in a query. The LIKE condition is used in the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement.Like clause is used as condition in SQL query. Like clause compares data with an expression using wildcard operators. It is used to find similar data from the table.LIKE is the ANSI/ISO standard operator for comparing a column value to another column value, or to a quoted string. Returns either 1 (TRUE) or 0 (FALSE).The SQL LIKE operator is only applied on a field of types CHAR or VARCHAR to match a pattern.To match a pattern from a word, special characters, and wildcards characters may have used with LIKE operator.The LIKE operator can be used within any valid SQL statement, such as SELECT, INSERT INTO,UPDATE or DELETE.SQL LIKE & Wildcard operators – LIKE operator in SQL is used with a WHERE clause to search specific patterns in a table column. To make searching effective, there are 2 wild card operators available in SQL which are used along with the LIKE operator.

LIKE Syntax

SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;


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 Like Operator

Here In This Step We Will Create Like Operator Using Where Clause.
Here We Will Pass Parameter Ccity LIKE 'M%'; Using Where Clause.
Here Is An List Of Example Related To Topic Like Operator Using Where Clause.So Follow All Example So You Can Get The Ideas Related To Topic In This Blog.

SELECT *
FROM Client_table_news 

WHERE Ccity LIKE 'M%';

SELECT *
FROM Client_table_news 

WHERE Ccity LIKE '%I';



SELECT * FROM Client_table_news

WHERE Ccity LIKE '%MUM%';



SELECT * FROM Client_table_news

WHERE Ccity LIKE '_UM%';



SELECT * FROM Client_table_news

WHERE Ccity LIKE 'M_%_%';



SELECT * FROM Client_table_news
WHERE Ccity LIKE 'M%I';


SELECT * FROM Client_table_news
WHERE Ccity NOT LIKE 'M%';



No comments:

Post a Comment