Searching for values that uses the same value
Example
SELECT Name, UnitPrice, Quantity, Color
FROM Product
WHERE Name Like '2' OR UnitPrice Like '2' OR Quantity LIKE '2' OR Color LIKE '2'
is there a way to shorten the sentence so that i do not need to repeat Variable LIKE ‘value’?
LIKEwithout wildcards is=This expands out to a series of OR conditions
Note that the string
'2'will be CAST as needed after OR expansionIf you do require wild cards and LIKE, you’d have to use a series of OR statements.
Finally, this won’t scale performance-wise. With good indexing, (eg one per column and other 2 as INCLUDE columns) then this would probably be better written as separate queries with UNION between them
Edit, for clarity
OP wants to use wildcards. Therefore my
INsuggestion will not work. So you have to do thisBecause of the leading wildcard, there is no point adding indexes. So my text above about indexes+includes is irrelevant