select * into temp from 表名 where 字段=f union select * from 表名 where 字段=b union select * from 表名 where 字段=i union select * from 表名 where 字段=hinsert into temp select * from 表名 where 字段 not in(f,b,i,h) order by 字段 asc
我觉得最好是你给这些记录加上编号,给你觉得最重要的记录加的编号如1,2,3,4.然后别的不重要的就无所谓了.如果记录很多的话,你可以按下边去做. 1.insert into #t select * from 表 where 字段 not in('f','b','i','h') 2.给表加上一个id列,自增长的.3.插入 insert 表(字段) select * from #t
select * from 表名 where 字段=b union all select * from 表名 where 字段=i union all select * from 表名 where 字段=h union all select * from 表名 where 字段 not in ('b,''i','h') order by 字段按照樓主的要求我也隻能這麼答了,期待高手
select * from table1 order by case col when 'f' then '1' when 'b' then '2' when 'i' then '3' when 'h' then '4' else col1 end
select * from 表 order by charindex(字段,'hibf') desc
select * from 表名 where 字段=b union all select * from 表名 where 字段=i union all select * from 表名 where 字段=h union all select * from 表名 where 字段 not in ('b,''i','h') order by 字段
还是老大的方法最好。Select * from 表 Order By CharIndex(字段,'hibf') Desc,字段
--測試 CREATE procedure p_orderby @s varchar(4000) as declare @str varchar(8000) declare @n int declare @i int set @i=1 set @n=len(@s) set @str='' while @n>0 begin set @str=@str+ 'select * from testB where Name = substring('+''''+@s+''''+','+cast(@i as varchar)+','+cast( 1 as varchar)+') union all ' set @i=@i+1 set @n=@n-1 end set @str=@str+'select * from testB where len('+''''+@s+''''+')=len(replace('+''''+@s+''''+',Name,'+''''''+')) ' exec(@str) GO --調用測試 exec p_orderby 'fbih'
贊同這種方法﹕ Select * from 表 Order By CharIndex(字段,'hibf') Desc,字段
半天沒來這么多人熱情,感動 zjcxc(邹建),真的行啊,可以實現,謝謝大家, 不過有個問題,好象不支持distinct來消除重復記錄啊,會出這樣的錯 ============== Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80040E21) ODBC driver does not support the requested properties. ============== 能實現加個消除重復記錄的功能不?謝謝
那这样改改Select * from (Select Distinct * from 表) A Order By CharIndex(Name,'hibf') Desc,Name
union
select * from 表名 where 字段=b
union
select * from 表名 where 字段=i
union
select * from 表名 where 字段=hinsert into temp select * from 表名 where 字段 not in(f,b,i,h) order by 字段 asc
1.insert into #t
select * from 表 where 字段 not in('f','b','i','h')
2.给表加上一个id列,自增长的.3.插入
insert 表(字段)
select * from #t
union all
select * from 表名 where 字段=i
union all
select * from 表名 where 字段=h
union all
select * from 表名 where 字段 not in ('b,''i','h') order by 字段按照樓主的要求我也隻能這麼答了,期待高手
order by charindex(字段,'hibf') desc
union all
select * from 表名 where 字段=i
union all
select * from 表名 where 字段=h
union all
select * from 表名 where 字段 not in ('b,''i','h') order by 字段
CREATE procedure p_orderby
@s varchar(4000)
as
declare @str varchar(8000)
declare @n int
declare @i int
set @i=1
set @n=len(@s)
set @str=''
while @n>0
begin
set @str=@str+ 'select * from testB where Name = substring('+''''+@s+''''+','+cast(@i as varchar)+','+cast( 1 as varchar)+') union all '
set @i=@i+1
set @n=@n-1
end
set @str=@str+'select * from testB where len('+''''+@s+''''+')=len(replace('+''''+@s+''''+',Name,'+''''''+')) '
exec(@str)
GO
--調用測試
exec p_orderby 'fbih'
Select * from 表 Order By CharIndex(字段,'hibf') Desc,字段
zjcxc(邹建),真的行啊,可以實現,謝謝大家,
不過有個問題,好象不支持distinct來消除重復記錄啊,會出這樣的錯
==============
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E21)
ODBC driver does not support the requested properties.
==============
能實現加個消除重復記錄的功能不?謝謝