Domanda

Sono bloccato cercando di combinare un like con un sinistra uni in Sybase.

Ad esempio (anche se nel mio caso è un po 'più complicato), sto cercando un testo che non contenga un o né un i.

Sono in grado di fare il contrario, cioè testo contenente una di queste lettere:

select numbers.name from 
(
      select 'one'   name union all
      select 'two'   name union all
      select 'three' name union all -- neither %o% nor %i%
      select 'four'  name union all
      select 'five'  name union all
      select 'six'   name union all
      select 'seven' name union all -- neither %o% nor %i%
      select 'eight' name union all
      select 'nine'  name union all
      select 'ten'   name           -- neither %o% nor %i%
) numbers,
(
      select '%o%'  expression union all
      select '%i%'  expression       
) patterns
where
  numbers.name like patterns.expression

Seleziona tutti i record tranne three, seven e ten come previsto.

Ora sto cercando un modo per trovare questi tre record. Ho pensato all'adesione a sinistra numeri insieme a modelli e poi filtrando sull'espressione è nullo. Qualcosa come questo:

numbers.name *like patterns.expression and
patterns.expression is null

Ovviamente, questo non funziona. Quindi, sarei felice per qualsiasi puntatore dato nella giusta direzione.

Per quello che vale, questa è la versione su cui sto lavorando:

select @@version
'Adaptive Server Enterprise/15.0.3/EBF 17156 ESD#3/P/Sun_svr4/OS 5.8/ase1503/2726/64-bit/FBO/Fri Feb  5 05:26:23 2010'
È stato utile?

Soluzione

Dovresti usare NOT EXISTS (è il caso):

select numbers.name from 
(
      select 'one'   name union all
      select 'two'   name union all
      select 'three' name union all -- neither %o% nor %i%
      select 'four'  name union all
      select 'five'  name union all
      select 'six'   name union all
      select 'seven' name union all -- neither %o% nor %i%
      select 'eight' name union all
      select 'nine'  name union all
      select 'ten'   name           -- neither %o% nor %i%
) numbers
where not exists (select null
                    from (
                             select '%o%'  expression union all
                             select '%i%'  expression
                         ) patterns
                   where numbers.name like patterns.expression)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top