create table A ( id indentity(1,1) num int )select * from A where id in(3,1,2)select * from A where id in(3,1,2) order by charindex(','+rtrim(id)+',',',3,1,2,')
应该和主键有关系 create table a(a varchar(1) primary key) insert into a select 'a' insert into a select 'd' insert into a select 'c'select * from acreate table b(b varchar(1)) insert into b select 'a' insert into b select 'd' insert into b select 'c'select * from bdrop table a,b
(
id indentity(1,1) num int
)select * from A where id in(3,1,2)select * from A where id in(3,1,2)
order by charindex(','+rtrim(id)+',',',3,1,2,')
create table a(a varchar(1) primary key)
insert into a select 'a'
insert into a select 'd'
insert into a select 'c'select * from acreate table b(b varchar(1))
insert into b select 'a'
insert into b select 'd'
insert into b select 'c'select * from bdrop table a,b
2.在没有order by的情况下,sqlserver不保证查询结果的顺序
3.楼主的问题可以通过加identity列来解决