Anthony Foschini Anthony Foschini - 5 months ago 20
SQL Question

Multiple Wildcards/Filters for SQL

I am attempting to only retrieve Business Unit specific information from a large datamart, and would like to structure my query to eliminate unrelated DepartmentIDs.

In plainspeak, the end goal is to filter on ALL DepartmentIDs starting with "AN" and ending in 0, P, A, N, R, V, C, L, W, E, or Y.

Currently the query starts with:

FROM bbms_tpirc.dbo.LaborDetailByName LaborDetailByName
WHERE (LaborDetailByName.post_year='2016') AND
(LaborDetailByName.center_id='APEEN') AND
(LaborDetailByName.loan Like 'AN%')


but I am struggling with the next section.

Using another
AND (LaborDetailByName.loan Like '%0', '%P')
etc doesn't return anything in the dataset. Might I be overfiltering, or simply forgetting an argument?

Answer

You can replace your filter clause

(LaborDetailByName.loan Like 'AN%')

with

(LaborDetailByName.loan Like 'AN%[OPANRVCLWEY]')