Related
I have a nasty, nasty data layout that I am forced to work with. I finally got a working query using C# and a for loop executing the same query over and over but adjusting which fields are called, but now I am wondering if it is possible to do it with a while loop. I am getting an error, and I am not sure if it is because I am using Faircom / C-tree as the database, or if there is something wrong with my query. I am normally a Mysql user.
the table has 20 fields I care about and want to extract into a csv list. They are codetype1-codetype20 and I want it to be something like value1, value2, value3... where as it is now I get them all back one at a time. Trouble is that codetype1 is dependent on another field to determine where I go look for the info on that code, which is why the case statements.
DROP PROCEDURE IF EXISTS proc_loop_test;
CREATE PROCEDURE proc_loop_test()
SET #index = 1;
WHILE(#index < 21) DO
SELECT Replace(Concat(To_char(apptid), To_char(.#index) ), ' ', '') AS reference_id,
apptid AS a_reference_id,
CASE
WHEN c.ee > 0 THEN d.amt
ELSE insfee.amt
END AS amount,
CASE
WHEN c.ee > 0 THEN Rtrim(e.moneyname)
ELSE insname.namefeecatid
END AS moneyschedule_name,
CASE codetype#index
WHEN 1 THEN rtrim(a.descript)
ELSE rtrim(b.descript0)
END AS description,
CASE codetype#index
WHEN 1 THEN rtrim(a.abbrevdescript)
ELSE rtrim(b.abbrev0)
END AS abbreviated_description,
CASE codetype#index
WHEN 1 THEN rtrim(a.thiscode)
ELSE rtrim(b.thiscode0)
END AS code
FROM meetings
LEFT JOIN
(
SELECT admin.table2.procid,
admin.table2.this_code_id,
admin.v_table1.descript,
admin.v_table1.abbrevdescript,
admin.v_table1.thiscode
FROM admin.table2
INNER JOIN admin.v_table1
ON admin.table2.this_code_id = admin.v_table1.this_code_id) AS a
ON meetings.codeid#index = a.procid
LEFT JOIN
(
SELECT admin.v_table1.descript AS descript0,
admin.v_table1.abbrevdescript AS abbrev0,
admin.v_table1.thiscode AS thiscode0,
admin.v_table1.this_code_id
FROM admin.v_table1) AS b
ON meetings.codeid#index = b.this_code_id
LEFT JOIN
(
SELECT patid AS id,
ee
FROM admin.customer) AS c
ON meetings.patid = c.id
LEFT JOIN
(
SELECT this_code_id AS redid,
eecategoryid,
amt
FROM admin.eeule) AS d
ON c.ee = d.eecategoryid
AND d.redid = b.this_code_id
LEFT JOIN
(
SELECT eecategoryid AS namefeecatid,
moneyname
FROM admin.eeulenames) AS e
ON d.eecategoryid = e.namefeecatid
LEFT JOIN (SELECT pi.customer_id,
pi.primarykk_id AS picid,
pi.primarykk_name,
pi.first_name,
pi.last_name,
i.groupname,
i.ee
FROM admin.v_pir AS pi
LEFT JOIN admin.money AS i
ON pi.primarykk_id = i.insid) AS
ins
ON ins.customer_id = c.id
LEFT JOIN (SELECT this_code_id AS redid,
eecategoryid,
amt
FROM admin.eeule) AS insfee
ON ins.ee = insfee.eecategoryid
AND insfee.redid = b.this_code_id
LEFT JOIN (SELECT eecategoryid AS namefeecatid,
moneyname
FROM admin.eeulenames) AS insname
ON insfee.eecategoryid = insname.namefeecatid
WHERE codeid#index >= 1
END WHILE;
END;
I have never used a while loop, and while I understand somewhat I am supposed to select this to go INTO something, do I need to create a temp table, or can it all just be stored in memory till the end of the loop and returned.
For what it is worth, the entire SELECT query works in C# when you replace the #index with concatenating format " . index . "
Based on the information that you have provided, it is strongly suggested that you reach out to your vendor for this. You're attempting to create a stored procedure, however, using a mySQL proprietary syntax. Stored procedure support is unique to each database vendor. FairCom's c-treeACE SQL actually uses Java for cross platform support and .NET for Windows.
https://docs.faircom.com/doc/jspt/#cover.htm
Stored procedure development requires a strong knowledge of the database layout which is highly application dependent. In this case, many legacy application dependencies may be involved. Again, your best source of information will be your application vendor.
SELECT PRODDTA.F4006.OADOCO, PRODDTA.F4006.OADCTO, PRODDTA.F4006.OAKCOO, PRODDTA.F4006.OAANTY, PRODDTA.F4006.OAMLNM, PRODDTA.F4006.OAADD1, PRODDTA.F4006.OAADD2, PRODDTA.F4006.OAADD3, PRODDTA.F4006.OAADD4, PRODDTA.F4006.OAADDZ, PRODDTA.F4006.OACTY1, PRODDTA.F4006.OACOUN, PRODDTA.F4006.OAADDS, PRODDTA.F4006.OACRTE, PRODDTA.F4006.OABKML, PRODDTA.F4006.OACTR, PRODDTA.F4006.OAUSER, PRODDTA.F4006.OAPID, PRODDTA.F4006.OAUPMJ, PRODDTA.F4006.OAJOBN, PRODDTA.F4006.OAUPMT, PRODDTA.F4006.OALNID
INTO #BAF4006ShipTo
FROM PRODDTA.F4006
WHERE (PRODDTA.F4006.OAANTY='2');
SELECT PRODDTA.F4211.SDKCOO, PRODDTA.F4211.SDDOCO, PRODDTA.F4211.SDDCTO, PRODDTA.F4211.SDAN8, PRODDTA.F4211.SDSHAN, PRODDTA.F4211.SDDOC, PRODDTA.F4211.SDDCT, PRODDTA.F4211.SDNXTR
INTO #BAFSumF4211byInvoice
FROM PRODDTA.F4211
GROUP BY PRODDTA.F4211.SDKCOO, PRODDTA.F4211.SDDOCO, PRODDTA.F4211.SDDCTO, PRODDTA.F4211.SDAN8, PRODDTA.F4211.SDSHAN, PRODDTA.F4211.SDDOC, PRODDTA.F4211.SDDCT, PRODDTA.F4211.SDNXTR
HAVING ((PRODDTA.F4211.SDKCOO='00035') AND (PRODDTA.F4211.SDNXTR='999'));
SELECT PRODDTA.F0018.TDCO, PRODDTA.F0018.TDDCTO, PRODDTA.F0018.TDDOCO, PRODDTA.F0018.TDAN8, PRODDTA.F0101.ABALPH, PRODDTA.F0116.ALADDS, (PRODDTA.F0018.TDAEXP/100) AS TDAEXP, (PRODDTA.F0018.TDATXN/100) AS TDATXN, (PRODDTA.F0018.TDATXA/100) AS TDATXA, (PRODDTA.F0018.TDSTAM/100) AS TDSTAM, PRODDTA.F0018.TDTXA1, PRODDTA.F0018.TDEXR1, PRODDTA.F0018.TDDGL, PRODDTA.F0018.TDDSVJ
INTO #BAFTaxQuery
FROM (PRODDTA.F0018 INNER JOIN PRODDTA.F0101 ON PRODDTA.F0018.TDAN8 = PRODDTA.F0101.ABAN8) INNER JOIN PRODDTA.F0116 ON PRODDTA.F0018.TDAN8 = PRODDTA.F0116.ALAN8
WHERE ((PRODDTA.F0018.TDCO='00035') AND (PRODDTA.F0018.TDDCTO='RI') AND (PRODDTA.F0018.TDDGL>114182 And PRODDTA.F0018.TDDGL<=114273));
SELECT #BAFTaxQuery.TDCO, #BAFTaxQuery.TDDCTO, #BAFTaxQuery.TDDOCO, #BAFSumF4211byInvoice.SDDOCO, #BAFSumF4211byInvoice.SDDCTO, #BAFTaxQuery.TDAN8, #BAFTaxQuery.ABALPH, #BAFTaxQuery.ALADDS, #BAFSumF4211byInvoice.SDSHAN, #BAFTaxQuery.TDAEXP, #BAFTaxQuery.TDATXN, #BAFTaxQuery.TDATXA, #BAFTaxQuery.TDSTAM, #BAFTaxQuery.TDTXA1, #BAFTaxQuery.TDEXR1, #BAFTaxQuery.TDDGL, #BAFTaxQuery.TDDSVJ
INTO #BAFTaxQuery2
FROM #BAFTaxQuery LEFT JOIN #BAFSumF4211byInvoice ON (#BAFTaxQuery.TDDOCO = #BAFSumF4211byInvoice.SDDOC) AND (#BAFTaxQuery.TDDCTO = #BAFSumF4211byInvoice.SDDCT);
SELECT #BAFTaxQuery2.TDCO, #BAFTaxQuery2.TDDCTO, #BAFTaxQuery2.TDDOCO, #BAFTaxQuery2.SDDOCO, #BAFTaxQuery2.SDDCTO, #BAFTaxQuery2.TDAN8, #BAFTaxQuery2.ABALPH as BAFTaxQuery2_ABALPH, #BAFTaxQuery2.ALADDS as BAFTaxQuery2_ALADDS, #BAFTaxQuery2.SDSHAN,PRODDTA.F0101.ABALPH as BAFTaxQuery3_ABALPH, PRODDTA.F0116.ALADDS as BAFTaxQuery3_ALADDS, #BAFTaxQuery2.TDAEXP, #BAFTaxQuery2.TDATXN, #BAFTaxQuery2.TDATXA, #BAFTaxQuery2.TDSTAM, #BAFTaxQuery2.TDTXA1, #BAFTaxQuery2.TDEXR1, #BAFTaxQuery2.TDDGL, #BAFTaxQuery2.TDDSVJ
INTO #BAFTaxQuery3
FROM #BAFTaxQuery2 INNER JOIN PRODDTA.F0101 ON #BAFTaxQuery2.SDSHAN = PRODDTA.F0101.ABAN8 INNER JOIN PRODDTA.F0116 ON #BAFTaxQuery2.SDSHAN = PRODDTA.F0116.ALAN8;
SELECT #BAFTaxQuery3.TDCO, #BAFTaxQuery3.TDDCTO, #BAFTaxQuery3.TDDOCO, #BAFTaxQuery3.SDDOCO, #BAFTaxQuery3.SDDCTO, #BAFTaxQuery3.TDAN8, #BAFTaxQuery3.BAFTaxQuery2_ABALPH, #BAFTaxQuery3.BAFTaxQuery2_ALADDS, #BAFTaxQuery3.SDSHAN, #BAFTaxQuery3.BAFTaxQuery3_ABALPH, #BAFTaxQuery3.BAFTaxQuery3_ALADDS,#BAFTaxQuery3.TDAEXP, #BAFTaxQuery3.TDATXN, #BAFTaxQuery3.TDATXA, #BAFTaxQuery3.TDSTAM, #BAFTaxQuery3.TDTXA1, #BAFTaxQuery3.TDEXR1, #BAFTaxQuery3.TDDGL, #BAFTaxQuery3.TDDSVJ, #BAF4006ShipTo.OAMLNM, #BAF4006ShipTo.OACTY1, #BAF4006ShipTo.OAADDS
INTO #BAFTaxReportQuery
FROM #BAFTaxQuery3 LEFT JOIN #BAF4006ShipTo ON (#BAFTaxQuery3.SDDCTO = #BAF4006ShipTo.OADCTO) AND (#BAFTaxQuery3.SDDOCO = #BAF4006ShipTo.OADOCO) AND (#BAFTaxQuery3.TDCO = #BAF4006ShipTo.OAKCOO);
DROP TABLE #BAF4006ShipTo
DROP TABLE #BAFTaxQuery
DROP TABLE #BAFTaxQuery2
DROP TABLE #BAFSumF4211byInvoice
DROP TABLE #BAFTaxQuery3
DROP TABLE #BAFTaxReportQuery
The Query runs fine in Sql Server.
I create shared dataset as 'Text' and I'm able to create successfully.
But in the report when I Add Dataset , there are no fields showing.
I tried adding it manually too but get this error. "THe shared Dataset definition is not valid. The report definition element 'Dataset' is empty at line 43,position 5. It is missing a mandatory chid elemnt of type 'Fields.'"
I need to fill some fields in a table getting informations from other records of the same table.
I tried to write a query to explain what I want to do:
update globale2
set
nita = t.nita,
tita = t.tita,
notaita = t.notaita
where
neng = t.neng and
nita is null
(select nita, neng, tita, notaita from globale where uris='mma' and nita is not null) as t
edit to eplain better:
every records have these fields: "nita", "tita", "notaita", "neng" ("neng" cannot be null)
I want to fill these fields: "nita", "tita", "notaita" (where "nita" is empty)
with the same values from another record where "neng" equals the other "neng"
You can however, join the two tables.
UPDATE globale2 g
INNER JOIN globale gg
ON g.neng = gg.neng
SET g.nita = gg.nita,
g.tita = gg.tita,
g.notaita = gg.notaita
WHERE g.nita IS NULL
AND gg.uris = 'mma'
AND gg.nita IS NOT NULL
assume there is a table A_temp, with two columns 'one' and 'two'.
TABLE A_temp
ONE TWO
1 2
this is the present status of the table.
The query
UPDATE (SELECT * FROM A_temp ) A SET one = A.two where one = '1'
updates the table as
ONE TWO
2 2
Hope you get the idea and that it helps..
I have problem with my mysl query. Response time is to long. My query:
SELECT SQL_CALC_FOUND_ROWS
t.id,
l.id_produkt_lista,
z.nr_zam,
k.nazwa_fv,
p.nazwa,
p.opis,
p.data_realizacji,
CONCAT(t.d_graf,'</br>', IF(t.D_d_graf IS NOT NULL,
DATE_FORMAT(t.D_d_graf, "%d-%m-%Y"),"")),
CONCAT(t.d_druk,'</br>', IF(t.D_d_druk IS NOT NULL,
DATE_FORMAT(t.D_d_druk, "%d-%m-%Y"),"")),
CONCAT(t.d_zgrz,'</br>', IF(t.D_d_zgrz IS NOT NULL,
DATE_FORMAT(t.D_d_zgrz, "%d-%m-%Y"),""))
FROM zamowienie_produkt_lista l
JOIN zamowienia_zamowienie z ON (l.id_zamowienie = z.id_zamowienie)
JOIN zamowienia_produkt p ON (l.id_produkt = p.id_produkt)
JOIN zamowienia_prac_tmp t ON (l.id_produkt = t.id_produkt)
JOIN zamowienia_klient k ON (z.id_klient = k.id_klient)
WHERE TRUE
AND id_typ_produkt = '1'
AND z.archiwum = 0
ORDER BY t.id
When I use it in phpmyadmin I have to wait about 10 second
Assuming that id_typ_produkt belongs to table zamowienie_produkt_lista, creating following indexes should help:
CREATE INDEX p_1_idx ON zamowienie_produkt_lista
(id_produkt, id_typ_produkt);
CREATE INDEX z_1_idx ON zamowienia_zamowienie
(id_zamowienie, archiwum);
You should also make sure that indexes on all *_id fields for all other joined tables exist.
When I do this:
select * from vw_active_employees where division IS NULL; --319 results
Makes sense. And, then I do this...
select * from vw_active_employees where division IS NULL AND udds IS NULL; -- over 1000 results
Whaaaaat?? MORE results??
So, I had to wrap the view as a subselect for it to return what I was expecting. Like this:
select vw_active_employees.* from (select * from vw_active_employees) tmp where division IS NULL AND udds IS NULL; --317 results
Can someone explain this? I've never had to do this in MS SQLSERVER - so this is foreign to me.
The SQL used to create this view actually joins a number of other views together. I'm not entirely sure it's helpful to see, but you asked for it :) It's basically
CREATE VIEW `vw_active_employees` AS
select
e.*,
`vw_employee_attributes_map`.`med_school_faculty`, `vw_employee_attributes_map`.`paid_clinic_faculty`, `vw_employee_attributes_map`.`volunteer_clinic_faculty`, `vw_employee_attributes_map`.`dept_vote_rights`, `vw_employee_attributes_map`.`emeritus`, `vw_employee_attributes_map`.`aoa_member`, `vw_employee_attributes_map`.`faculty_senate`, `vw_employee_attributes_map`.`faculty_senator_elect`, `vw_employee_attributes_map`.`faculty_senator_alt_elect`, `vw_employee_attributes_map`.`exec_comm_member`, `vw_employee_attributes_map`.`ucc`, `vw_employee_attributes_map`.`icc`, `vw_employee_attributes_map`.`va`, `vw_employee_attributes_map`.`uwmf`, `vw_employee_attributes_map`.`affiliate`, `vw_employee_attributes_map`.`aurora`, `vw_employee_attributes_map`.`website_searchable`,
`vw_employee_current_appointment_info`.`termination_date`, `vw_employee_current_appointment_info`.`last_promotion_date`, `vw_employee_current_appointment_info`.`promotion_due_date`, `vw_employee_current_appointment_info`.`last_reappointment_date`, `vw_employee_current_appointment_info`.`reappointment_duration`, `vw_employee_current_appointment_info`.`reappointment_due_date`, `vw_employee_current_appointment_info`.`non_renewal_date`, `vw_employee_current_appointment_info`.`roster`, `vw_employee_current_appointment_info`.`payroll`, `vw_employee_current_appointment_info`.`on_probation`, `vw_employee_current_appointment_info`.`probation_complete`, `vw_employee_current_appointment_info`.`probation_notify_sent_date`, `vw_employee_current_appointment_info`.`probation_end_date`, `vw_employee_current_appointment_info`.`uw_appointment_id`, `vw_employee_current_appointment_info`.`effective_date`, `vw_employee_current_appointment_info`.`percent`, `vw_employee_current_appointment_info`.`end_date`, `vw_employee_current_appointment_info`.`continuity_status`, `vw_employee_current_appointment_info`.`guaranteed_length`, `vw_employee_current_appointment_info`.`end_reason`, `vw_employee_current_appointment_info`.`midterm_eval_received`, `vw_employee_current_appointment_info`.`final_eval_received`, `vw_employee_current_appointment_info`.`annual_eval_letter_sent`, `vw_employee_current_appointment_info`.`annual_eval_sent_date`, `vw_employee_current_appointment_info`.`annual_eval_received`, `vw_employee_current_appointment_info`.`annual_eval_received_date`, `vw_employee_current_appointment_info`.`probation_month_done`, `vw_employee_current_appointment_info`.`seniority_date`, `vw_employee_current_appointment_info`.`represented`, `vw_employee_current_appointment_info`.`work_schedule`, `vw_employee_current_appointment_info`.`evaluation_end_date`, `vw_employee_current_appointment_info`.`evaluation_month_end`, `vw_employee_current_appointment_info`.`evaluation_sent_date`, `vw_employee_current_appointment_info`.`evaluation_completed`, `vw_employee_current_appointment_info`.`hiring_pi`, `vw_employee_current_appointment_info`.`appointment_type`, `vw_employee_current_appointment_info`.`appointment_type_code`, `vw_employee_current_appointment_info`.`appointment_classified`, `vw_employee_current_appointment_info`.`termination_type`, `vw_employee_current_appointment_info`.`head`, `vw_employee_current_appointment_info`.`secretary`, `vw_employee_current_appointment_info`.`division`, `vw_employee_current_appointment_info`.`supervisor_first_name`, `vw_employee_current_appointment_info`.`supervisor_last_name`, `vw_employee_current_appointment_info`.`title`, `vw_employee_current_appointment_info`.`title_code`, `vw_employee_current_appointment_info`.`udds`, `vw_employee_current_appointment_info`.`udds_code`,
`vw_employee_current_background_info`.`visa_holder`, `vw_employee_current_background_info`.`visa_type`, `vw_employee_current_background_info`.`visa_expiration_date`, `vw_employee_current_background_info`.`license`, `vw_employee_current_background_info`.`license_exp_date`, `vw_employee_current_background_info`.`dea`, `vw_employee_current_background_info`.`dea_expiration_date`, `vw_employee_current_background_info`.`national_provider_number`, `vw_employee_current_background_info`.`residency_location`, `vw_employee_current_background_info`.`residency_end_date`, `vw_employee_current_background_info`.`fellowship_location`, `vw_employee_current_background_info`.`fellowship_end_date`, `vw_employee_current_background_info`.`primary_board_cert`, `vw_employee_current_background_info`.`primary_cert_date`, `vw_employee_current_background_info`.`specialty_board_cert`, `vw_employee_current_background_info`.`specialty_cert_date`, `vw_employee_current_background_info`.`degree_info_reports`, `vw_employee_current_background_info`.`healthlink_id`, `vw_employee_current_background_info`.`uwmf_general_ledger_id`, `vw_employee_current_background_info`.`uwmf_employee_id`, `vw_employee_current_background_info`.`specialty`,
`vw_employee_current_compliance_info`.`hipaa_training_completed`, `vw_employee_current_compliance_info`.`sic_training_completed`, `vw_employee_current_compliance_info`.`background_check_completed`, `vw_employee_current_compliance_info`.`i9_completed`, `vw_employee_current_compliance_info`.`caregiver_applies`, `vw_employee_current_compliance_info`.`caregiver_check_completed`, `vw_employee_current_compliance_info`.`tb_completed`, `vw_employee_current_compliance_info`.`rubella_immunity_comfirmed`, `vw_employee_current_compliance_info`.`respiratory_test_completed`, `vw_employee_current_compliance_info`.`health_link`, `vw_employee_current_compliance_info`.`access_request_uwhc`, `vw_employee_current_compliance_info`.`rn_credentialing`, `vw_employee_current_compliance_info`.`bls_cert_expiration`, `vw_employee_current_compliance_info`.`uwhc_cred_submitted`,
`vw_employee_current_contact_info`.`employee_id`, `vw_employee_current_contact_info`.`ext_office`, `vw_employee_current_contact_info`.`area_code_office`, `vw_employee_current_contact_info`.`number_office`, `vw_employee_current_contact_info`.`country_code_office`, `vw_employee_current_contact_info`.`ext_home`, `vw_employee_current_contact_info`.`area_code_home`, `vw_employee_current_contact_info`.`number_home`, `vw_employee_current_contact_info`.`country_code_home`, `vw_employee_current_contact_info`.`address1_office`, `vw_employee_current_contact_info`.`address2_office`, `vw_employee_current_contact_info`.`city_office`, `vw_employee_current_contact_info`.`state_office`, `vw_employee_current_contact_info`.`zip_office`, `vw_employee_current_contact_info`.`mail_code_office`, `vw_employee_current_contact_info`.`address1_home`, `vw_employee_current_contact_info`.`address2_home`, `vw_employee_current_contact_info`.`city_home`, `vw_employee_current_contact_info`.`state_home`, `vw_employee_current_contact_info`.`zip_home`, `vw_employee_current_contact_info`.`email`
from employee e
left join vw_employee_attributes_map on e.id = vw_employee_attributes_map.employee_id
left join vw_employee_current_appointment_info on e.id = vw_employee_current_appointment_info.employee_id
left join vw_employee_current_background_info on e.id = vw_employee_current_background_info.employee_id
left join vw_employee_current_compliance_info on e.id = vw_employee_current_compliance_info.employee_id
left join vw_employee_current_contact_info on e.id = vw_employee_current_contact_info.employee_id
where e.active = 1
And the vw_employee_current_appointment_info which contains 'division' and 'udds' looks like:
CREATE VIEW `vw_employee_current_appointment_info` AS
select e.id as `employee_id`,
`appointment`.`termination_date`, `appointment`.`last_promotion_date`, `appointment`.`promotion_due_date`, `appointment`.`last_reappointment_date`, `appointment`.`reappointment_duration`, `appointment`.`reappointment_due_date`, `appointment`.`non_renewal_date`, `appointment`.`roster`, `appointment`.`payroll`, `appointment`.`on_probation`, `appointment`.`probation_complete`, `appointment`.`probation_notify_sent_date`, `appointment`.`probation_end_date`, `appointment`.`uw_appointment_id`, `appointment`.`effective_date`, `appointment`.`percent`, `appointment`.`end_date`, `appointment`.`continuity_status`, `appointment`.`guaranteed_length`, `appointment`.`end_reason`, `appointment`.`midterm_eval_received`, `appointment`.`final_eval_received`, `appointment`.`annual_eval_letter_sent`, `appointment`.`annual_eval_sent_date`, `appointment`.`annual_eval_received`, `appointment`.`annual_eval_received_date`, `appointment`.`probation_month_done`, `appointment`.`seniority_date`, `appointment`.`represented`, `appointment`.`work_schedule`, `appointment`.`evaluation_end_date`, `appointment`.`evaluation_month_end`, `appointment`.`evaluation_sent_date`, `appointment`.`evaluation_completed`, `appointment`.`hiring_pi`,
`appointment_type`.`name` as `appointment_type`, `appointment_type`.`code` as `appointment_type_code`, `appointment_type`.`classified` as `appointment_classified`,
`termination`.`name` as `termination_type`,
`appointment_division`.`head`, `appointment_division`.`secretary`,
`division`.`division_name` as `division`,
`supervisor`.`first_name` as `supervisor_first_name`, `supervisor`.`last_name` as `supervisor_last_name`,
`title`.`name` as `title`, `title`.`code` as `title_code`,
`udds`.`name` as `udds`, `udds`.`code` as `udds_code`
from employee e
left join appointment on appointment.employee_id = e.id and appointment.primary = 1
left join appointment_type on appointment.appointment_type_id = appointment_type.id
left join termination on appointment.termination_id = termination.id
left join appointment_division on appointment_division.appointment_id = appointment.id and appointment_division.primary = 1
left join division on appointment_division.division_id = division.id
left join appointment_supervisor on appointment_supervisor.appointment_id = appointment.id and appointment_supervisor.primary = 1
left join employee supervisor on appointment_supervisor.supervisor_id = supervisor.id
left join appointment_title on appointment_title.appointment_id = appointment.id and appointment_title.primary = 1
left join title on appointment_title.title_id = title.id
left join appointment_udds on appointment_udds.appointment_id = appointment.id and appointment_udds.primary = 1
left join udds on udds.id = appointment_udds.udds_id
you have used left join in your tables .when join condition is true than it has been select records those match in all tables than fetch records from left tables one by one and in this case your null condition is true and it is repeat the result set view
You are using left joins so your base table connects to the subsequent tables even if no value exists. However, when you begin to filter the subsequent tables you are specifying a that the subsequent table contain certain values. In this case there are probably only 319 values in the "vw_employee_current_appointment_info" with a null in the division field. When you add in the udds field there can be more fields that are null, because of the left join the division field is NULL by definition
So, the number of connections where "vw_employee_current_appointment_info" has udds as NULL is greater than the number of records where division is NULL, so it brings them all back. If you try this with equal joins then the number will be 319 max.