Hello!

I can’t create a seemingly simple procedure, I hope I can explain and you will help ... There are two tables:

Table1(PodrazdId,DolgnostId,KolichestvoDolgn) Table2(NomerSotrudnika,PodrazdId,DolgnostId)

Next, I present the table fragments:

Table1

1, 17, 2 - i.e. in subdivision 1 with position code 17 there are 2 vacancies

But, in Table2 this entry:

130, 1, 17 - i.e. the person with code number 130 works in 1 department at the position of 17

I need a procedure that shows a list of possible vacancies, i.e. in this case there is another free space for this position. It is clear that the IDs compare in the two tables, but how to prescribe a condition for KolichestvoDolgn?

  • and be sure to procedure ??? - Artem

1 answer 1

 SELECT DepID, PositionID, VacationsCount - (SELECT COUNT(PeopleID) FROM TAble2 t2 WHERE t1.PositionId = t2.PositionID AND t1.DepID = t2.DepID ) FROM Table1 t1 
  • thanks a lot !!! - wicS