The problem was that the statement was missing parenthesis
tags as follows:
and ('#ReReplaceNoCase(socNum, '[^0-9]', '', 'All')#'
IN
(tch_socsecnum,math_tchname_ssn,eng_tchname_ssn,socstud_tchname_ssn,sci_tchname_ssn,read_tchname_ssn)
or oth_tchname_ssn like '%#ReReplaceNoCase(socNum, '[^0-9]',
'', 'All')#%' )
We also indexed some columns. I will eventually swtich this
to a stored procedure. It runs quite fast now.
Thanks for your help.