Umm maybe something like...
SELECT
cusName,
cellPerBlock,
case when cell >= cellPerBlock then block + (cell / cellPerBlock) when cell < 0 then block - ((floor((cell * -1) / cellPerBlock))*1) else block end 'block',
case when cell >= cellPerBlock then floor(cell / cellPerBlock) when cell < 0 then cell + (cellPerBlock * ((floor((cell * -1) / cellPerBlock))*1)) else cell end 'cell'
FROM [tbCus]
or if you need the group by clause, use a nested query
FROM
(
SELECT cusName, cellPerBlock, SUM(block) 'block', SUM(cell) 'cell' FROM [tbCus] GROUP BY cusName, cellPerBlock
)
Since you said a query, I kept it as one statement.
I replaced the while loop with what I think a mathematical equivalent is. (I had to make some assumptions about your data)
So for the while loop
while (cell < 0)
{
cell += cellPerBlock;
block--;
}
cell = -10
cellPerBlock = 2
block = 10
Result: cell = 0, block = 5
In the query,
when cell < 0 then cell + ((cellPerBlock * ((floor((cell * -1)/ cellPerBlock))*1)) else cell end 'cell'
cell = -10 + (2 * ((-10*-1) % 2)*1) = 0
when cell < 0 then block - ((floor((cell * -1)/cellPerBlock))*1) else block end 'block'
block = 10 - (((-10*-1) % 2)*1) = 5
The *1 at the end is to handle the event when your while loop would have ran once but my formula would deliver a quotient of 0. I think my brackets and maths is right, not tested it.