------解决方案-------------------- --> 测试数据:#tb
IF OBJECT_ID('TEMPDB.DBO.#tb') IS NOT NULL DROP TABLE #tb
GO
CREATE TABLE #tb([col] NUMERIC(12,4))
INSERT #tb
SELECT 1.234 UNION ALL
SELECT 1 UNION ALL
SELECT 2.45 UNION ALL
SELECT 5 UNION ALL
SELECT 3.1
--------------开始查询--------------------------
SELECT [col]=CASE WHEN CEILING([col])=[col] THEN LTRIM(CEILING([col])) ELSE LTRIM([col]) END FROM #tb
----------------结果----------------------------
/*
col
1.2340
1
2.4500
5
3.1000
*/
是这个样子吗 ------解决方案-------------------- select case when 数字%1>0 then 数字%1 else 数字 end ------解决方案--------------------
SELECT [col]=CAST(CAST([col] AS FLOAT)AS VARCHAR(10)) FROM #tb
------解决方案--------------------
SELECT cast([col] as float)[col] FROM #tb
------解决方案--------------------
create table #temp(
qty decimal(12,4)
)
insert into #temp
select 1
union select 1.12
union select 1.234
union select 1.2342
union select 1.3
select case
when right(qty,4)='0000' then left(qty,len(qty)-5)
when right(qty,3)='000' then left(qty,len(qty)-3)
when right(qty,2)='00' then left(qty,len(qty)-2)
when right(qty,2)<>'00' and right(qty,1)='0' then left(qty,len(qty)-1)
else left(qty,len(qty)) end "查询结果",qty "原数据" from #temp