check out the NTILE function. Split the set of data (calls not done or unasigned calls or however you want to do it - your data is not clear) then you will have a tile (or bucket if you prefer). You can then select your callers and assign a number (using ROW_NUMBER) to them and join to the tiles.

Get the number of open calls for A and B. Get the number of unassigned calls. Take the difference between A & B. Assign that number (difference) of calls to the Caller with the least open calls. Then if there is any remaining unassigned calls divid by 2 and divy them out to each caller, perhaps adding some logic for any left over calls.

ntile deals with that but you might have to count first then do the sql work dynamically - I can't remember if ntile accepts variables.but basically you need to do what I said even if you do a count(*) calls/count(*) callers or somerthing first then a row_number. Your question and example data don't make it easy enough for me to do the work for you so you'll have to do some reading and see what is appropriate.Paste some usable data and that might change...

It sounds like you might need some sort of "Best Fit" Algorithm. If I understand what you are trying to do then, bascially, you are going to need to get the get a set of all callers that are currently assigned calls that are not done. Then get all the calles to be assigned. Then you need to deterime now you want to distribute those calls.... Do you start with the caller with the lowest number of not done calls and assign "new" calls to them until the are equal with the call with the next greatest number of calls and so on? Or do you just assign one to everyone?

-- This section is to find the lowest number of calls still to make per caller The caller must retain his oldest call that were not completed.

Set @MIN = (SELECT top 1 MIN(call) from (SELECT caller AS user, COUNT( * ) AS call FROM telephone WHERE Present is null AND Refuse is null AND caller is not NULL Group by caller Union SELECT caller.user, 0 AS call FROM caller LEFT JOIN telephone ON caller.user = telephone.caller WHERE caller.Actif='1' AND caller.user not in (SELECT caller FROM telephone WHERE Present is null AND Refuse is null AND caller is not NULL) Group BY user) o group by call order by call)

-- This section find one caller with the least amount of calls to make.

Set @ENS = (SELECT TOP 1 user from (SELECT caller AS user, COUNT( * ) AS call FROM telephone WHERE Present is null AND Refuse is null AND caller is not NULL Group by caller Union SELECT caller.user, 0 AS call FROM caller LEFT JOIN telephone ON caller.user = telephone.caller AND caller.Actif='1' WHERE caller.Actif='1' AND caller.user not in (SELECT caller FROM telephone WHERE Present is null AND Refuse is null AND caller is not NULL) Group BY user) o WHERE call = @MIN)

-- This section assign a call to the caller

UPDATE telephone SET caller=@ENS Where number=@ID

END

If you have a more elegant way to dot it, any suggestion is welcome.This solution is actually working well.