order by charindex(col,'1.1,1.1.1,1.1.2,1.1.3,1.2,1.3')>0
不行吧,能这样?用IDENTITY来试试
order by charindex(','+RTRIM(col)+',',',1.1,1.1.1,1.1.2,1.1.3,1.2,1.3,')
order by lie*10 desc
declare @a varchar(100) set @a = '1.1,1.1.1,1.1.2,1.4,1.2.1,1.1.3,1.2,1.3' declare @tb table ( id int identity(1,1), val varchar(5) ) while charindex(',',@a)>0 begin insert into @tb select replace(left(@a,charindex(',',@a)),',','') set @a = right(@a, len(@a)-charindex(',',@a)) end insert into @tb select @adeclare @max_len int select @max_len = max(len(val)) from @tb select id, left(val + replicate('.0',@max_len),@max_len) from @tb order by left(val + replicate('.0',@max_len),@max_len) 應該是這個意思吧,補一下‘.0’然后排序就可以了
order by lie*10 desc
declare @a varchar(100)
set @a = '1.1,1.1.1,1.1.2,1.4,1.2.1,1.1.3,1.2,1.3'
declare @tb table
(
id int identity(1,1),
val varchar(5)
)
while charindex(',',@a)>0
begin
insert into @tb
select replace(left(@a,charindex(',',@a)),',','')
set @a = right(@a, len(@a)-charindex(',',@a))
end
insert into @tb
select @adeclare @max_len int
select @max_len = max(len(val)) from @tb
select id, left(val + replicate('.0',@max_len),@max_len)
from @tb
order by left(val + replicate('.0',@max_len),@max_len)
應該是這個意思吧,補一下‘.0’然后排序就可以了
不好意思,是我没说清楚。这些是表中的一列值,按这列值的这种顺序进行排序。就像我们写word文档中的多级符号,