I have an SQL with around 50 “OR” condition and all with “Like” operator. I execute this SQL from a VB Access code.
But the query fails saying, “Expression Too Long” error (mostly I think, because it exceeds 1024 characters in the query grid.
SELECT *
FROM <My Database>
WHERE (
[Title] = ''
OR [Title] = ''
OR [Title] = ''
OR [Title] = ''
OR [Title] = ''
OR [Title] = ''
OR [Title] = ''
OR [Title] = ''
OR [Title] = ''
OR [Title] = ''
)
AND (
[TITLE] LIKE '*Afghanistan*'
OR [TITLE] LIKE '*Term1*'
OR [TITLE] LIKE '*Term2*'
OR [TITLE] LIKE '*Term3*'
OR ..<around 40 like these>
OR [COUNTRY] LIKE '*Country1*'
OR ...<around 40 like these>
);
Any ideas or suggestions as to how to work around this issue?
Suggestions: insert parameter values into base “staging” tables (possibly in another temp database) and create seni joins to these tables using
EXISTS. UseALIKE(rather thanLIKE), which always uses Standard SQL wildcard characters (%).