String manipulation query

I need a request for the next problem. Table 1 shows the required input fields. I will get fields with inactive = "No" and the field "mant" = "yes"

So, I have 4 entries with fields like sev, sev1, cde, frt.

Table1:

Fields                 Inactive              mandt_field

sev                     no                      yes
sev1                    no                      yes
sev2                    yes                     yes
abd                     no                       no
cde                     no                      yes
frt                     no                      yes

Table 2 shows data similar to this.

concession           add_fields

TH-123               -sev*yes-sev1*no-sev2*yes
Th-234               -sev*yes-sev1*yes-cde*yes-frt*no
Th-345               -sev*yes-cde*yes-frt*no
TH-456               -cde*no-frt*no
Th-012               -sev*no-sev1*no-cde*no-frt*no
Th-451               -frt*yes
TH-900               -sev2*no

Now I need records that do not have the above 4 fields in add_fields. the output should return the following entries: - TH-123, Th-345, TH-456, Th-451, TH-900.

These 4 records do not have all 4 fields that we extracted from the previous table (sev, sev1, cde, frt).

No. The fields obtained in table1 may vary. Since they are taken from the table data ... so we can have (sev, sev1, cde, frt ....)

+3
2

SELECT DISTINCT concession
FROM Table2
INNER JOIN Table1 ON Table2.add_fields NOT LIKE '%-' + Table1.Fields + '*%'
WHERE Inactive='no' AND mandt_field='yes'

, add_fields, , . , , yes/no. 2 . .

, . .

concession    code    YesNo
----------------------------
TH-123        sev       yes
TH-123        sev1      no
TH-123        sev2      yes
Th-234        sev       yes
....
+2

: , .

2, , , . add_fields , Table1

: SQL , (mandelbrot, T-SQL). , .

0

Source: https://habr.com/ru/post/1761469/


All Articles