TROB TROB - 24 days ago 9
SQL Question

Using Like with additional criteria

Seems simple, but I can't get any results with this query:

WHERE
WKSHT_CD like 'E2%' AND
(LINE_NUM = '01100' OR
LINE_NUM = '01300' OR
LINE_NUM = '01700' OR
LINE_NUM = '01701') AND
(CLMN_NUM = '00100' OR
CLMN_NUM = '00200')


The wildcard works by itself, but when combined with additional criteria it returns nothing.

Sam Sam
Answer

Try this:

WHERE 
WKSHT_CD like 'E2%' 
AND LINE_NUM in('01100', '01300', '01700', '01701') 
AND CLMN_NUM in('00100', '00200')

As long as the table has at least one row that matches all of your criteria, this will work.

edit: based on the sample data you commented with, try this instead:

WHERE 
WKSHT_CD like 'E2%' 
AND LINE_NUM in('01100', '01300', '01700', '01701') 
AND CLMN_NUM in('0100', '0200')