Butterblume
Benutzer
- Beiträge
- 13
Oh, ich sehe gerade, dass ich was falsches geschrieben habe. Ich will natürlich entgültig zwei Tabellen daraus erstellen. Einmal für Firmen und einmal für Personen. Sorry!
Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
WITH tabelle(zeile,AdressID,FirmaID,PersonID,Adresstyp,Gelöscht) AS (
SELECT ROW_NUMBER() OVER (ORDER BY FirmaID,AdressID,Adresstyp),
AdressID,FirmaID,PersonID,Adresstyp,Gelöscht
FROM LinkAdressen
WHERE Gelöscht IS NULL
)
SELECT t1.AdressID,t1.FirmaID,t1.Adresstyp,t1.PersonID,t1.Adresstyp
FROM tabelle t1
WHERE EXISTS ( SELECT 1
FROM tabelle t2
WHERE isnull(t2.FirmaID,0) = isnull(t1.FirmaID,0)
AND isnull(t2.AdressID,0) = isnull(t1.AdressID,0)
AND isnull(t2.PersonID,0) = isnull(t1.PersonID,0)
AND t1.zeile != t2.zeile
AND ( t2.Adresstyp = t1.Adresstyp
OR t1.Adresstyp IS NULL ) )
ORDER BY t1.AdressID,t1.FirmaID,t1.PersonID,t1.Adresstyp
AND ( t2.Adresstyp = t1.Adresstyp)