将十进制数据类型转换为整数。
SELECT CAST(x_coord AS INT)
FROM dbo.RMCP
编辑: 我更新了代码以反映如何更改数据类型。这是一个很大的影响变化,所以要非常小心。我会敦促您在开发中对此进行测试。
if object_id('#Demo') is not null
drop table #Demo;
go
create table #Demo(x_coord decimal(12,5))
insert into #Demo values(5588790.77000),(5588873.79000),(5588943.71000)
alter table #Demo
ALTER COLUMN x_coord INT NULL
select *
from #Demo
GO
- 或者这有效
if object_id('#Demo') is not null
drop table #Demo;
go
create table #Demo(x_coord decimal(12,5))
insert into #Demo values(5588790.77000),(5588873.79000),(5588943.71000)
alter table #Demo
add new_x_coord INT NULL
UPDATE #Demo SET new_x_coord = CAST(x_coord AS INT)
GO
--********************** dont drop anything until you confirm the data is good!!!!!!!!!!!!! and test this in development *************************************
ALTER TABLE #Demo
DROP COLUMN x_coord
exec sp_rename 'dbo.#Demo.new_x_coord','x_coord','COLUMN'
select *
from #Demo
GO