当前位置: 代码迷 >> Sql Server >> 这个能用动态sql改写上不
  详细解决方案

这个能用动态sql改写上不

热度:40   发布时间:2016-04-25 01:22:12.0
这个能用动态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

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