使用 SQL Server 2000
表格1
ID column1 column2 (datatype is nvarchar)
001 08.50 17.50
002 17.20 16.52
003 09.50 01.00
....
我想从 table1 中删除零,例如 8.5 17.5 ....
预期输出
ID column1 column2
001 8.5 17.5
002 17.2 16.52
003 9.5 1
....
这个怎么做。
需要 Sql 查询帮助
使用 SQL Server 2000
表格1
ID column1 column2 (datatype is nvarchar)
001 08.50 17.50
002 17.20 16.52
003 09.50 01.00
....
我想从 table1 中删除零,例如 8.5 17.5 ....
预期输出
ID column1 column2
001 8.5 17.5
002 17.2 16.52
003 9.5 1
....
这个怎么做。
需要 Sql 查询帮助
重新设计数据库,使列的类型适合其中包含的数据。
例子:
select cast (017.50 as float)
你应该使用浮点数,因为如果你使用数字,它需要一个比例,如果比例大于数字的比例,它不会删除结尾的零。例如:
select cast (017.50 as numeric(10,2)) = 17.50
如果你这样做10,1,它会像 16.52 这样四舍五入,所以浮点数是最好的选择
执行选择时将您的列转换为编号
尝试这个 :
select cast(1234.20 as float ) //1234.2
select cast(01.00 as float ) //1
select cast(17.5 as float ) //17.5
select cast(00.01 as float ) //0.01
select cast(00.10 as float ) //0.1
you could always get the values with php and trim() the zero's and commas out
then update your sql
that is if for some reason you cannot or dont want to change your sql's data types