首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

bom清单分级编号排序有关问题

2012-09-01 
bom清单分级编号排序问题字段说明no_id 想要生成的序号part_id物料编号,parent_id父类编号,qty用量,lev层

bom清单分级编号排序问题


字段说明
no_id 想要生成的序号part_id物料编号,parent_id父类编号,qty用量,lev层级,sort_id每层中的各自序号
想通过这样的想法实现,但不知代码如何写
当为第一层时no_id直接=sort_id,以后层级的no_id = 父类的no_id + '.' + sort_id 来实现
1
1.1
1.2
2
2.1
2.1.1
2.2
这样的效果,得到这样的序号后不知道怎样才能这样的排序效果,因为不能直接order by no_id,10会和1放在一起,而把2后到后面的

[解决办法]

SQL code
declare @tb table (id varchar(20))insert into @tb select '1' union allselect '2.1' union allselect '1.1' union allselect '2' union allselect '10' union allselect '2.1.1' union allselect '1.1.1' union allselect '1.1.2' union allselect '10.1' union allselect '3' select * from @tb order by  case when charindex('.',id)=0 then CAST( id AS int)           else cast(isnull(LEFT(id,charindex('.',id)-1),id)  as int) end,idid11.11.1.11.1.222.12.1.131010.1
[解决办法]
上面办法不能解决全部情况,第2位大于10就到了

可以参考http://blog.csdn.net/xys_777/archive/2010/06/15/5672481.aspx

热点排行