34,590
社区成员
发帖
与我相关
我的任务
分享
select * from tb
order by charindex(rtrim(Kid),'39,23,21,41,121,44,123')
select * from tb
order by charindex(','+rtrim(Kid)+',',',39,23,21,41,121,44,123,')
create table # (i int)
insert # select 39
insert # select 41
insert # select 121
insert # select 21
insert # select 44
insert # select 123
insert # select 23
select * from #
order by charindex(','+ltrim(i)+',',','+'39,23,21,41,121,44,123'+',')
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([col] int)
insert [TB]
select 39 union all
select 41 union all
select 121 union all
select 21 union all
select 44 union all
select 123 union all
select 23
select [col] from [TB] order by charindex(rtrim([col]),'39,23,21,41,121,44,123')
/*
col
-----------
39
23
21
41
121
44
123
(7 行受影响)
*/
drop table TB
前后加逗号
order by charindex(','+rtrim(Kid)+',',','+'39,23,21,41,121,44,123'+',')