Need help on the Bin Packing algorithm used in http://www.sqlteam.com/Forums/pop_printer_friendly.asp?TOPIC_ID=141721

I am working on a problem similar to the one addressed in the old forum. I came across the post from 'SwePeso' but I am not able to understand it completely.

What does this formula 'COALESCE(s.recID / (s.Yak * s.Unq / s.Items), 0) % s.Items' does?

Thanks

COALESCE gives the first non-null value, while % is modulo which gives you the remainder.

Thanks for the reply @djj55 , I understand that bit. I want to know how it fits in the larger picture when it is used in the 'Bin Packing' algorithm used at http://www.sqlteam.com/Forums/pop_printer_friendly.asp?TOPIC_ID=141721 .

Peter's code isn't a "BIN Stacking" algorithm. It's a permutation algorithm.

Are you really trying to solve a "BIN Stacking" problem because a permutation algorithm probably isn't the way to go for this. The number of permutations grow explosively and if you have more than a handful of items to stack in more than a handful of bins, it could easily take longer than a well written loop.