日期:2014-05-16  浏览次数:20463 次

找到小数点后面不为0的数
请教下,怎么查询出小数点后面不为0的数?
例如
NUM    AET
1     13.11
2     1.00
3     4.34
5     7.0
6     9.0

怎么查询出AET中小数点后面不为0的 13.11和4.34  

谢谢!
------解决方案--------------------
----------------------------------------------------------------
-- Author  :DBA_HuangZJ(发粪涂墙)
-- Date    :2014-03-05 11:15:09
-- Version:
--      Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) 
-- Apr  2 2010 15:48:46 
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[huang]
if object_id('[huang]') is not null drop table [huang]
go 
create table [huang]([NUM] int,[AET] numeric(4,2))
insert [huang]
select 1,13.11 union all
select 2,1.00 union all
select 3,4.34 union all
select 5,7.0 union all
select 6,9.0
--------------生成数据--------------------------

select * from [huang]
WHERE SUBSTRING(CAST(aet AS VARCHAR) ,CHARINDEX('.',CAST(aet AS VARCHAR))+1,LEN(CAST(aet AS VARCHAR)))<>0
----------------结果----------------------------
/* 
NUM         AET
----------- ---------------------------------------
1           13.11
3           4.34
*/

------解决方案--------------------
create table tb([NUM] int,[AET] decimal(4,2))
insert into tb
select 1,13.11 union all
select 2,1.00 union all
select 3,4.34 union all
select 5,7.0 union all
select 6,9.0
go
select * from tb where CEILING(aet)!=aet
/*
NUM         AET
----------- ---------------------------------------
1           13.11
3           4.34

(2 行受影响)

*/
go
drop table tb

------解决方案--------------------
select * from [tb] WHERE CAST(aet AS INT)<>aet