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

如果小弟我的排序字段里有百分号该如何写呢

2012-02-01 
如果我的排序字段里有百分号该怎么写呢比如说select*fromtb_testorderbyacasc其中ac的值都为52.2%65.4%54.

如果我的排序字段里有百分号该怎么写呢
比如说select   *   from   tb_test   order   by   ac   asc
其中   ac   的值都为     52.2%     65.4%     54.8%
该怎么排序呢
直接这样写。   好像排序不起作用。

[解决办法]
select * from tb_test order by Convert(float,replace(ac, '% ', ' ')) asc

[解决办法]
create table temp (A int, B int, C varchar(10))
insert temp
select 10, 3, '4.5% ' union all
select 31, 9, '3.2% ' union all
select 12, 8, '2.1% '


select * from temp order by left(c,len(c)-1) asc
[解决办法]
可以起作用啊

declare @tb_test table(ac varchar(10))
insert into @tb_test
select '52.2% '
union select '65.4% '
union select '54.8% '

select * from @tb_test order by ac asc

[解决办法]
select * from tb_test order by Convert(numeric(9,2),replace(ac, '% ', ' ')) asc
[解决办法]
select * from tb_test order by Cast(replace(ac, '% ', ' ') as numeric(9,2)) asc

热点排行
Bad Request.