This is my query with OR LIKE
in the where clause.
SELECT DISTINCT TOP 10 coalesce(cl2desc, hmdesc, gendesc, procdesc) as description,acctcode,uacs FROM
hpatchrg as t4 INNER JOIN
hcharge AS t5 ON t4.chargcode = t5.chrgcode LEFT JOIN
hmisc AS t6 ON t6.hmcode = t4.itemcode AND t5.chrgtable = 'MISCE' LEFT JOIN
hdmhdr AS t7 ON (t7.dmdcomb +''+ convert(varchar, t7.dmdctr)) = t4.itemcode AND t5.chrgtable = 'DRUGS' LEFT JOIN
hdruggrp AS t8 ON t7.grpcode = t8.grpcode LEFT JOIN
hgen AS t9 ON t9.gencode = t8.gencode LEFT JOIN
hprocm AS t10 ON t4.itemcode = t10.proccode AND t5.chrgtable = 'EXAMI' LEFT JOIN
hclass2 AS t11 ON t4.itemcode = t11.cl2comb AND t5.chrgtable = 'NONDR'
WHERE
(cl2desc LIKE '%cbc%') OR
(hmdesc LIKE '%cbc%') OR
(gendesc LIKE '%cbc%') OR
(procdesc LIKE '%cbc%')
This takes forever to return anything but when I do:
SELECT DISTINCT TOP 10 coalesce(cl2desc, hmdesc, gendesc, procdesc) as description,acctcode,uacs FROM
hpatchrg as t4 INNER JOIN
hcharge AS t5 ON t4.chargcode = t5.chrgcode LEFT JOIN
hmisc AS t6 ON t6.hmcode = t4.itemcode AND t5.chrgtable = 'MISCE' LEFT JOIN
hdmhdr AS t7 ON (t7.dmdcomb +''+ convert(varchar, t7.dmdctr)) = t4.itemcode AND t5.chrgtable = 'DRUGS' LEFT JOIN
hdruggrp AS t8 ON t7.grpcode = t8.grpcode LEFT JOIN
hgen AS t9 ON t9.gencode = t8.gencode LEFT JOIN
hprocm AS t10 ON t4.itemcode = t10.proccode AND t5.chrgtable = 'EXAMI' LEFT JOIN
hclass2 AS t11 ON t4.itemcode = t11.cl2comb AND t5.chrgtable = 'NONDR'
WHERE
(cl2desc LIKE '%cbc%')
also tried changing the (cl2desc LIKE '%cbc%')
with other value
I get result very fast.
So i assume that the problem is with the
OR LIKE
in the where clause
What is the correct way to do OR with LIKE in the where clause