In SQL Server like command is basically used for use wild card character in where clause.The most useful wild character is % . But what happen when in our column already contains % in column data.Have a look for example.In this example i created the case where we can easily understand about this scenario.
Sql server escape % sign
DECLARE
@ProductTotals TABLE
(
NAME varchar(100)
)
INSERT INTO @ProductTotals(NAME)
VALUES('Rac%h'),('Pasc%h'),('Rasc%h'),('Jac%h'),('Sachh'),('kancha')
-- I want to
fetch all record which have c%h
SELECT * FROM @ProductTotals
WHERE NAME like
'%c%h%'
SELECT * FROM @ProductTotals
WHERE NAME like
'%c[%]h%'
-- if we exeucte
first query then it return all record but when we
-- execute second one then its give
exact result.
0 comments:
Post a comment