Pregunta

I haven't quite found an answer to this problem, it seems a bit tricky (and yes, I am a beginner). I have two tables; eb_site and eb_register and they both have the column id_glo which connects them. The values within these fields are not quite the same though, the number is the connecting factor. An example:

eb_site = kplus.hs.dlsn.3074823

eb_register = kplus.hs.register.3074823-1"

How could I select the ones ie make a list where the number in eb_register deviates from the number in eb_site (and disregard the mismatch between dlsn/register).

And also where the eb_register has a -1 at the end as in the example (the fixed ones don't have the -1 at the end).

Thanks for any replies.

edit: oops sorry guys, worded it badly, have edited

Rgds,

Steinar

¿Fue útil?

Solución

the quality of the solution will depend on the possible id_glo values and the sql dialect you can use. as a start, try

    select s.id_glo
         , r.id_glo
      from eb_site     s
inner join eb_register r on (     replace(replace(s.id_glo, 'kplus.hs.register.', ''), 'kplus.hs.dlsn.', '') <> replace(replace(r.id_glo, 'kplus.hs.register.', ''), 'kplus.hs.dlsn.', '')
                              and replace(replace(r.id_glo, 'kplus.hs.register.', ''), 'kplus.hs.dlsn.', '') not like replace(replace(s.id_glo, 'kplus.hs.register.', ''), 'kplus.hs.dlsn.', '') || '-%'
           )
         ;

this query assumes that:

  • there are no more different prefixes as the ones you've given
  • number complements will only occur in records from eb_register

Otros consejos

If the numbers match, then the reverse of the numbers match. The following extracts the number (and final decimal point) from each key, using SQL Server syntax:

select *
from eb_site s join
     eb_register r
     on left(REVERSE(s.id_glo), charindex('.', reverse(s.id_glo))) =
        left(REVERSE(r.id_glo), charindex('.', reverse(r.id_glo)))

In other databases the charindex() might need to be replaced by another function, such as instr(), location(), or position().

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top