to me on the basis of what you stated I would utilize a loop and scalar function
I wouldset each level as an increment in a loop. For each increment send to the function, the level and the values associated with that level.
The scalar function would carry all logic for the levels.
Based on the above I am only giving you what is off the top of my head as I feel your question lacks some further detail to answer the question more specifically.
while loop tsql
WHILE (Transact-SQL) - SQL Server | Microsoft Docs[
^]
create function tsql
[
^]