Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

LIKE operator returns all records with wild card (%) in MS SQL Server

$
0
0

Hi,

I have 2 SQL query like below.

1. select * from mytest where 'abc' LIKE mycol.

2. select * from mytest where mycol LIKE 'abc'.

"mytest" is a table with "mycol" a column in it. The table has records with "mycol" containing values with SQL Server wild card e.g. %, %%, %a% etc. 

The query "1" returns me all 3 records with %, %% and %a% as "mycol" values, whereas query "2" does not return any record.

I am looking for an explanation how does 2 query works? What are the differenes between the two queries? Seems like the wild card values stored in "mycol" column are behaving like a wild card instead of literal when matching to literal 'abc' in case query "1".

Thanks,

Sachin


Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>