简体   繁体   中英

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?

You can replace your filter clause

(LaborDetailByName.loan Like 'AN%')

with

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

在SQL Server或MySQL中,可以使用RIGHT()

AND RIGHT(LaborDetailByName.loan,1) in ('0','P','A','N','R','V','C','L','W','E','Y')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM