I write some queries like this:
SELECT *
FROM Sample.dbo.Temp
WHERE
Name LIKE '%ab%'
OR Name LIKE '%fg%'
OR NAME LIKE '%asd%'
OR ...
OR ...
OR Name LIKE '%kj%'
Is there anyway I can rewrite this query like this:
SELECT *
FROM Sample.dbo.Temp
WHERE
Name LIKE (
'%ab%'
OR '%fg%'
OR '%asd%'
OR ...
OR ...
OR '%kj%'
)
Just looks more comfortable both from a readability point of view and manageability. If the column Name changes, I can always make one change instead of a hundred (or using Find and Replace). Any suggestions?
No, you have to keep repeating the
LIKEAlthough you could probably fool around a bit to make it work something like that, it won’t be prettier or more readable.
Perhaps you should generate the query programmatically instead of manually writing this?
PS: perhaps a fulltext index is a better idea here?