Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Filter items from a list
    primarykey
    data
    text
    <p>I need to filter out rows within a SQL table which has values in one column that are in a specified list of values. The simplified table looks something like: (Sorry for the bad formatting, never posted here before)</p> <pre><code>Error Codes | Other Column 1 | Other Column 2 ... -------------------------------------------------- F010,F123,F345, | ...... | ..... F231,FC85,F904, | ...... | ..... FC432,F0425,NA, | ...... | ..... .... </code></pre> <p>I first split the Error Codes column to get each of the 3 error codes, which is a comma separated string of values. Then I need to filter out rows with all three error codes within a given list such as ('F010', 'FC542', 'FB943'). I am running this on a Teradata DB, this is the portion of the query, but does not seem to be filtering out all combinations within the list:</p> <pre><code>SELECT ... , CASE WHEN ( substr(a.error_code, 1, position(',' in a.error_code)-1) in ('F010', 'FC542', 'FB012' 'FB943', 'NA') AND substr(a.error_code, position(',' in a.error_code)+1, position(',' in substr(a.error_code, position(',' in a.error_code)+1, Characters(a.error_code)-position(',' in a.error_code)))-1) in ('F010', 'FC542', 'FB012' 'FB943', 'NA') AND substr(a.error_code, position(',' in a.error_code) + position(',' in substr(a.error_code, position(',' in a.error_code)+1, Characters(a.error_code)-position(',' in a.error_code)))+1, Characters(a.error_code)-(position(',' in a.error_code) + position(',' in substr(a.error_code, position(',' in a.error_code)+1, Characters(a.error_code)-position(',' in a.error_code))))-1) in ('F010', 'FC542', 'FB012' 'FB943', 'NA') ) THEN 'No' ELSE 'Yes' end Error_Module, ... FROM Error_code_table a WHERE Error_Module = 'Yes' </code></pre> <p>As a side, the Characters() function is the same as Length().</p> <p>Thanks, Mike</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload