| Detta villkor är uppfyllt... | ...om denna SQL... | ...returnerar | ... och eventuell kommentar. |
|---|---|---|---|
| civilbtyp = 1 -> civil != 1: händelsen FÖDELSE kan endast starta tillståndet OGIFT, inga andra tillstånd - förutom när tillståndet OGIFT avslutas med ologiskt händelse, SKILSMÄSSA(4), PARTNERS DÖD(5) |
select count(*)
from K136.CIVILSTAND a
-- logiska sluthändelser (1,2,3,6) ger CIVIL = 1
where (civilbtyp = 1 and civilstyp in (1,2,3,6)
and civil != 1)
-- ologiska sluthändelser (4,5) ger CIVIL = 0
or (civilbtyp = 1 and civilstyp in (4,5)
and civil != 0 )
|
0 | |
| civilbtyp = 2 -> civil != 2: händelsen LYSNING kan endast starta tillståndet FÖRLOVAD, inga andra tillstånd - förutom när tillståndet FÖRLOVAD avslutas med ologiskt händelse, LYSNING(2), SKILSMÄSSA(4) |
select count(*)
from K136.CIVILSTAND a
-- logiska sluthändelser (1,3,5,6) ger CIVIL = 2
where (civilbtyp = 2 and civilstyp in (1,3,5,6)
and civil != 2)
-- ologiska sluthändelser (2,4) ger CIVIL = 0
or (civilbtyp = 2 and civilstyp in (2,4)
and civil != 0 )
|
0 | |
| civilbtyp = 3 -> civil != 3: händelsen VIGSEL kan endast starta tillståndet GIFT, inga andra tillstånd - förutom när tillståndet GIFT avslutas med ologiskt händelse, LYSNING(2), VIGSEL(3) |
select count(*)
from K136.CIVILSTAND a
-- logiska sluthändelser (1,4,5,6) ger CIVIL = 3
where (civilbtyp = 3 and civilstyp in (1,4,5,6)
and civil != 3)
-- ologiska sluthändelser (2,3) ger CIVIL = 0
or (civilbtyp = 3 and civilstyp in (2,3)
and civil != 0 )
|
0 | |
| civilbtyp = 4 -> civil != 4: händelsen SKILSMÄSSA kan endast starta tillståndet FRÅNSKILD, inga andra tillstånd - förutom när tillståndet FRÅNSKILD avslutas med ologiskt händelse, SKILSMÄSSA(4), PARTNERS DÖD(5) |
select count(*)
from K136.CIVILSTAND a
-- logiska sluthändelser (1,2,3,6) ger CIVIL = 4
where (civilbtyp = 4 and civilstyp in (1,2,3,6)
and civil != 4)
-- ologiska sluthändelser (4,5) ger CIVIL = 0
or (civilbtyp = 4 and civilstyp in (4,5)
and civil != 0 )
|
0 | |
| civilbtyp = 5 -> civil not in (0,1,2,3,4,5): händelsen PARTNERS DÖD kan starta samtliga tillstånd. Det gäller dock särskilda förutsättningar som måste kontrolleras separat. |
select count(*)
from K136.CIVILSTAND a
where (civilbtyp = 5
and civil not in (0,1,2,3,4,5) )
|
0 | |
| civilbtyp = 5 - specifik kontroll: om händelsen är PARTNERS DÖD och det föregåendet tillståndet är GIFT kan det följande tillståndet endast vara ÄNKA/ÄNKLING eller OKÄND |
with temp as (
select a.ddbid, a.civilnr,
a.civilbtyp civilbtyp_1, kba.kodnmn start_1,
a.civil civil_1, kca.kodnmn civilstand_1,
b.civilbtyp civilbtyp_2, kbb.kodnmn start_2,
b.civil civil_2, kcb.kodnmn civilstand_2,
c.civilbtyp civilbtyp_3, kbc.kodnmn start_3,
c.civil civil_3, kcc.kodnmn civilstand_3
from K136.CIVILSTAND a
left join kod.kodcivil kca on a.civil = kca.kod
left join kod.KODCIVILBTYP kba
on a.CIVILBTYP = kba.kod
left join K136.CIVILSTAND b
on a.ddbid = b.ddbid
and a.civilnr = b.civilnr-1
left join kod.kodcivil kcb
on b.civil = kcb.kod
left join kod.KODCIVILBTYP kbb
on b.CIVILBTYP = kbb.kod
left join K136.CIVILSTAND c
on b.ddbid = c.ddbid
and b.civilnr = c.civilnr-1
left join kod.kodcivil kcc
on c.civil = kcc.kod
left join kod.KODCIVILBTYP kbc
on c.CIVILBTYP = kbc.kod
order by a.civilnr
)
select count(*)
from temp
where civilbtyp_3 = 5
and civil_2 = 3
and civil_3 not in (0, 5)
|
0 | |
| civilbtyp = 5 - specifik kontroll: om händelsen är PARTNERS DÖD och det föregåendet tillståndet är FÖRLOVAD ska egentligen det följande tillståndet motsvara det tillstånd som gäller före tillståndet förlovad. Det finns dock vissa förutsättningar som ändrar på detta:
|
with temp as (
select a.ddbid, a.civilnr,
a.civilbtyp civilbtyp_1, kba.kodnmn start_1,
a.civil civil_1, kca.kodnmn civilstand_1,
b.civilbtyp civilbtyp_2, kbb.kodnmn start_2,
b.civil civil_2, kcb.kodnmn civilstand_2,
c.civilbtyp civilbtyp_3, kbc.kodnmn start_3,
c.civil civil_3, kcc.kodnmn civilstand_3
from K136.CIVILSTAND a
left join kod.kodcivil kca
on a.civil = kca.kod
left join kod.KODCIVILBTYP kba
on a.CIVILBTYP = kba.kod
left join K136.CIVILSTAND b
on a.ddbid = b.ddbid
and a.civilnr = b.civilnr-1
left join kod.kodcivil kcb
on b.civil = kcb.kod
left join kod.KODCIVILBTYP kbb
on b.CIVILBTYP = kbb.kod
left join K136.CIVILSTAND c
on b.ddbid = c.ddbid
and b.civilnr = c.civilnr-1
left join kod.kodcivil kcc
on c.civil = kcc.kod
left join kod.KODCIVILBTYP kbc
on c.CIVILBTYP = kbc.kod
order by a.civilnr, a.ddbid
)
select count(*)
from temp
where civilbtyp_3 = 5 and
civil_2 = 2 and
(civil_3 != civil_1 and
civil_3 != 0 and
civil_3 != 5)
|
0 | |
| civilbtyp = 6 -> civil not in (0,1,2,3,4,5,6): händelsen PSEUDOHÄNDELSE kan starta samtliga tillstånd |
select count(*)
from K136.CIVILSTAND a
where (civilbtyp = 6 and
civil not in (0,1,2,3,4,5,6) )
|
0 | |
| civilstyp = 1 -> civil not in (0,1,2,3,4,5,6): händelsen EGEN DÖD kan avsluta samtliga tillstånd |
select count(*)
from K136.CIVILSTAND a
where (civilstyp = 1 and
civil not in (0,1,2,3,4,5,6) )
|
0 | |
| civilstyp = 2 -> civil not in (0,1,4,5,6): händelsen LYSNING kan endast avsluta tillstånden OKÄND, OGIFT, ÄNKA/ÄNKLING, FRÅNSKILD, ÄNKA/ÄNKLING/SKILD, dvs. inte FÖRLOVAD, GIFT |
select count(*)
from K136.CIVILSTAND a
where (civilstyp = 2 and
civil not in (0,1,4,5,6) )
|
0 | |
| civilstyp = 3 -> civil not in (0,1,2,4,5,6): händelsen VIGSEL kan endast avsluta tillstånden OKÄND, OGIFT, FÖRLOVAD, ÄNKA/ÄNKLING, FRÅNSKILD, ÄNKA/ÄNKLING/SKILD, dvs. inte GIFT |
select count(*)
from K136.CIVILSTAND a
where (civilstyp = 3 and
civil not in (0,1,2,4,5,6) )
|
0 | |
| civilstyp = 4 -> civil not in (3,0): händelsen SKILSMÄSSA kan endast avsluta tillståndet GIFT och i vissa fall OKÄNT, inga andra tillstånd. |
select count(*)
from K136.CIVILSTAND a
where (civilstyp = 4 and civil not in (3,0))
|
0 | |
| civilstyp = 5 -> civil not in (2,3,0): händelsen PARTNERS DÖD kan endast avsluta tillstånden FÖRLOVAD, GIFT och i vissa fall OKÄNT, inga andra tillstånd. |
select count(*)
from K136.CIVILSTAND a
where (civilstyp = 5 and civil not in (2,3,0) )
|
0 | |
| civilstyp = 6 -> civil not in (0,1,2,3,4,5,6): händelsen PSEUDOHÄNDELSE kan avsluta samtliga tillstånd. |
select count(*)
from K136.CIVILSTAND a
where (civilstyp = 6 and civil not in (0,1,2,3,4,5,6) )
|
0 |