Here are rows in my database which I want to get:
I want to get get all 3 rows by executing one query, this ids are received as procedure parameters, sometimes I can receive 1 id and sometimes I can receive 10 of them, depends what users sends to database.
I wrote something like this:
SELECT *
FROM Products
WHERE CONVERT(NVARCHAR(MAX), ProductId) LIKE '%' + 'A9472294-CFDD-40AC-BC2D-00E39AF4A300, 9A817E40-E4B1-4487-A376-010DD6377E38, 078A3C75-C442-4D88-A1E0-0118B8706667' + '%'
SELECT *
FROM Products
WHERE 'A9472294-CFDD-40AC-BC2D-00E39AF4A300, 9A817E40-E4B1-4487-A376-010DD6377E38, 078A3C75-C442-4D88-A1E0-0118B8706667' LIKE '%' + CONVERT(NVARCHAR(MAX), ProductId) + '%'
How come the second example returns rows as expected and the first example does not return any rows?
The definition says: %or% finds any values that have "or" in any position
How does this actually work? Could anyone explain?
EDIT:
I thought this LIKE operator should be used on my column like
Select * From Products Where ProductId Like '%' + 'SomeStringId' + '%';
because LIKE operator is used in a WHERE clause to search for a specified pattern in a column and my column is ProductId
so I can't understand how come example like this works:
Select * From Products Where 'SomeStringId' Like '%' + ProductId + '%';
How come this example above works if Like is not used on my column, it's used on some string acctually...