日期:2014-05-17  浏览次数:20635 次

这个能用动态sql改写下不
RT
select 
a.一级编码,
a.一级名称,
b.二级编码,
b.二级名称,
c.三级编码,
c.三级名称,
d.四级编码,
d.四级名称,
e.五级编码,
e.五级名称
from 

(select cinvccode as 一级编码 ,cinvcname as 一级名称 from InventoryClass ic
where ic.cinvccode like '1%' and iinvcgrade=1) a 

left join 
(select cinvccode as 二级编码 ,cinvcname as 二级名称 from InventoryClass ic
where ic.cinvccode like '1%' and iinvcgrade=2
) b on charindex( a. 一级编码 ,b.二级编码,1)=1

left join 
(select cinvccode as 三级编码 ,cinvcname as 三级名称 from InventoryClass ic
where ic.cinvccode like '1%' and iinvcgrade=3) c on charindex( b.二级编码 ,c.三级编码,1)=1


left join 
(select cinvccode as 四级编码 ,cinvcname as 四级名称 from InventoryClass ic
where ic.cinvccode like '1%' and iinvcgrade=4) d on charindex( c.三级编码 ,d.四级编码,1)=1

left join 
(select cinvccode as 五级编码 ,cinvcname as 五级名称 from InventoryClass ic
where ic.cinvccode like '1%' and iinvcgrade=5) e on charindex( d.四级编码 ,e.五级编码,1)=1

------解决方案--------------------
先把要求说一下,该成什么样的?参数是什么?