insert  into  @t    
select    
    a.ID,a.PID,@i    
from    
    BOM  a,@t  b --a是表BOM的别名,b是表变量@t的别名,分别替代这两个表的原名称,目的是为了节约代码长度  
where    
    a.PID=b.ID  and  b.Level  =  @i-1