| Detta villkor är uppfyllt... | ...om denna SQL... | ...returnerar | ... och eventuell kommentar. |
|---|---|---|---|
| Alla värden på CIVILSTYP ska finnas i kodtabellen, kod.KODCIVILSTYP |
select count(*)
from K136.CIVILSTAND c
where c.CIVILSTYP not in
(select kc.KOD from kod.KODCIVILSTYP kc)
|
0 | |
| Alla värden i kodtabellen, kod.KODCIVILSTYP, ska finnas representerade i CIVILSTYP |
select count(*)
from kod.KODCIVILSTYP kc
where kc.KOD not in
(select c.CIVILSTYP from K136.CIVILSTAND c)
|
0 | |
| Om CIVILSTYP = 1 (Egen död) måste personen ha en dödsnotering i DB eller NOSTYP = 2 i sv.HL |
with temp as (
Select
i.DDBID i_DDBID
from sv.individ i
left join sv.db d on d.postnr = i.postnr
left join sv.hl h on h.postnr = i.postnr
left join sv.person p on i.ddbid = p.ddbid
where (d.postnr > 0 or h.nostyp = 2 or p.doddat > 0)
and i.ddbid is not null
)
Select count(*)
from K136.CIVILSTAND c
where c.CIVILSTYP = 1
and c.ddbid not in (select t.i_ddbid from temp t)
|
0 | |
| Om CIVILSTYP = 2 (Lysning) måste personen ha ett lysningsdatum i LV |
with temp as (
Select c.DDBID
from K136.CIVILSTAND c
left join sv.individ i on i.DDBID = c.DDBID
left join sv.lv l on l.postnr = i.postnr
where l.LYSDAT > 0
and i.ddbid is not null
)
select count(*)
from K136.CIVILSTAND a
where a.CIVILSTYP = 2
and a.DDBID not in (select t.ddbid from temp t)
|
0 | |
| Om CIVILSTYP = 3 (Vigsel) måste personen ha ett vigseldatum i LV eller ett vigseldatum i sv.HLCIV |
with temp as (
Select c.DDBID
from K136.CIVILSTAND c
left join sv.individ i on i.DDBID = c.DDBID
left join sv.lv l on l.postnr = i.postnr
left join sv.hlciv hc on hc.postnr = i.postnr
where l.VIGDAT > 0 or (hc.CIVHLTYP = 1 and hc.CIVHLDAT > 0)
and i.ddbid is not null
)
select count(*)
from K136.CIVILSTAND a
where a.CIVILSTYP = 3
and a.DDBID not in (select t.ddbid from temp t)
|
0 | |
| Om CIVILSTYP = 4 (Skilsmässa) måste personen ha en notering om upplösningsorsak skilsmässa i sv.HLCIV Alternativt måste partnern ha UPLORS = 2 i SV.HLCIV. |
with temp as (
Select c.DDBID
from K136.CIVILSTAND c
left join sv.individ i on i.DDBID = c.DDBID
left join sv.hlciv hc on hc.postnr = i.postnr
and hc.CIVHLTYP = 2
left join sv.rel r on i.ddbid = r.ddbid1
and rtyp = 3
left join sv.individ ri on r.ddbid2 = ri.ddbid
left join sv.hlciv rhc on rhc.postnr = ri.postnr
and rhc.CIVHLTYP = 2
where (hc.UPLORS = 2 or rhc.UPLORS = 2)
and i.ddbid is not null
)
select count(*)
from K136.CIVILSTAND a
where a.CIVILSTYP = 4
and a.DDBID not in (select t.ddbid from temp t)
|
0 | |
Om CIVILSTYP = 5 (Partners död) måste personen ha en partner som har dödsdatum i sv.PERSON och
|
with temp as (
Select i.DDBID i_DDBID
from sv.individ i
left join sv.REL r on i.ddbid = r.ddbid1 and r.rtyp = 3
left join sv.PERSON pper on pper.ddbid = i.ddbid
left join sv.PERSON ppart on ppart.ddbid = r.ddbid2
where (ppart.doddat > 0 and
(
ppart.doddat < pper.doddat or pper.doddat = 0 or
(ppart.doddat >= pper.doddat and ppart.doddat/10000 = pper.doddat/10000 )
) )
and i.ddbid is not null --and i.ddbid = 20011697
)
Select count(*)
from K136.CIVILSTAND c
where c.CIVILSTYP = 5
and c.ddbid not in (select t.i_ddbid from temp t)
|
0 |