Moien
Normalerweise sieht man SQL-Abfragen ja an was sie tun, aber diesmal…
Das Monster hier wurde mir vorgesetzt. Es fällt auch das richtige raus. Aber wieso weiss keiner. Kennt jemand einen Formater/Tool der mir das in Unterabfragen imt Zwischenresultaten aufdrösselt ? Geht um MS SQL.
SELECT cicntp.cnt_id, cicntp.cmp_wwn, CONVERT(smallint,CASE WHEN cicntp.cnt_id = cicmpy.cnt_id THEN 1 ELSE 0 END) AS Main, cicntp.active_y, WebAccess, pred.abbreviation, cicntp.initials, cicntp.fullname, cicntp.cnt_f_tel, cicntp.cnt_f_mobile, cicntp.cnt_job_desc, cicntp.cnt_dept, cicntp.textfield1, cicntp.textfield2, cicntp.textfield3, cicntp.textfield4, cicntp.textfield5, CAST((SELECT CASE WHEN EXISTS(SELECT ContactPerson FROM Addresses WHERE Type=‚VIS‘ AND Addresses.ContactPerson=cicntp.cnt_id) THEN 1 ELSE 0 END) AS tinyint) AS VIS, CAST((SELECT CASE WHEN EXISTS(SELECT ContactPerson FROM Addresses WHERE Type=‚POS‘ AND Addresses.ContactPerson=cicntp.cnt_id) THEN 1 ELSE 0 END) AS tinyint) AS POS, CAST((SELECT CASE WHEN EXISTS(SELECT ContactPerson FROM Addresses WHERE Type=‚DEL‘ AND Addresses.ContactPerson=cicntp.cnt_id) THEN 1 ELSE 0 END) AS tinyint) AS DEL, CAST((SELECT CASE WHEN EXISTS(SELECT ContactPerson FROM Addresses WHERE Type=‚INV‘ AND Addresses.ContactPerson=cicntp.cnt_id) THEN 1 ELSE 0 END) AS tinyint) AS INV, cicntp.cnt_email, cicntp.taalcode FROM cicntp INNER JOIN Pred on pred.predcode = cicntp.predcode INNER JOIN cicmpy ON cicntp.cmp_wwn=cicmpy.cmp_wwn WHERE cicntp.cmp_wwn = ? ORDER BY cicntp.active_y DESC
Danke