The easiest way may be to create a query in the database that returns employee and department information and hook one database component up to the query rather than the db tables. This creates, in effect, a flat file database where each employee's department information is listed in record for the employee. You'll then need to script your HotDocs template to sort on the department and only include the department information where it changes (logic is basically: is the first repeat or is the department name different from the previous repeat, if so, include department info).
Another approach is to create two db components, one for the department table, and one for the employee table. Then use scripting in the HotDocs template to map the employee variables to the nested repeat. You need to have two sets of employee vars--one set that you connect to the db, which is a simple level one repeat. The other set will be nested in the department repeat. Your scripting needs to SET the values in the nested repeat from the answers in the db connected employee repeat.
Neither approach is simple to implement, but first is probably simpler, depending on exactly how you need to use the answers in the template.
// Computation to take detail records retrieved through the DB// connection, and properly relate the detail records to the// appropriate master records.// This is necessary, because HotDocs does not associate master // and detail records properly. The issue is that HotDocs DOES NOT// use two or more levels of reference values when pulling info // from the DB connection into a nested dialog (contrary to// the instructions in the HotDocs manual)ASK UNANSWERED// Pull the master records from the database.// The variables linked to the database are also// contained in a dialog named "Master-dlg"ASK Master-db// Set the master record counter to zeroSET MasterCounter-n TO 0REPEAT Master-dlg // Increment the master record counter SET MasterCounter-n TO MasterCounter-n + 1 // Set the filter to pull the appropriate detail records // for this master record SET ThisMasterID-n TO MasterID-n // Pull the appropriate detail records from the database. // The variables linked to the database are also // contained in a dialog named "Detailed-tmp-dlg", which is // nested on "Master-dlg" ASK Detail-db // Check how many detail records were retrieved. // If there are any, we must copy the detail records // to the correct location(s). SET DetailCount-n TO COUNT( Detail-tmp-dlg ) IF DetailCount-n > 0 // Set a value in the target dialog "Detail-dlg" in the record // equal to the total number of detail records which were // retrieved for this master record SET DetailText-t [ MasterCounter-n, DetailCount-n ] TO "x" END IF // Repeat the target dialog "Detail-dlg", which is also // nested on "Master-dlg" REPEAT Detail-dlg // Set each value in the target nested dialog from the value // in the source nested dialog SET DetailDate-d TO DetailDate-tmp-d [ COUNTER ] SET DetailDate-tmp-d [ COUNTER ] TO UNANSWERED SET DetailText-t TO DetailText-tmp-t [ COUNTER ] SET DetailText-tmp-t [ COUNTER ] TO UNANSWERED [One line for each variable taken from the source nested dialog to the target nested dialog] END REPEATEND REPEATASK DEFAULT