| Author |
Topic |
|
pmosca
Starting Member
3 Posts |
Posted - 2010-04-22 : 11:55:16
|
| I am trying to figure out a way to write a SELECT query to see if the third decimal is NOT a zero.For example, if a column contains a number 34.0340, then I want to list all of these records. If a column contains 34.2300 then I do not want those. can that be done?thanksPablo MoscaIT ManagerTrinity Stairs, Inc. |
|
|
malpashaa
Constraint Violating Yak Guru
264 Posts |
Posted - 2010-04-22 : 12:18:50
|
Try this:CAST(CAST(34.2309 AS DECIMAL(9, 5)) * 1000 AS INT) % 10 |
 |
|
|
pmosca
Starting Member
3 Posts |
Posted - 2010-04-22 : 12:23:10
|
| I am trying to search multiple tables for numbers that contain a third decimal not equal to zero.the columns are numeric.For example...if the column contains 34.02001232.0560234.4400451232.123I want to list only records 1232.0560 and 451232.123is that possible? Pablo MoscaIT ManagerTrinity Stairs, Inc. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-22 : 12:41:31
|
whereSUBSTRING(SUBSTRING(CAST(your_col AS VARCHAR),CHARINDEX('.',CAST(your_col AS VARCHAR))+1,LEN(CAST(your_col AS VARCHAR))),3,1) <> '0' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-04-22 : 12:48:16
|
| DECLARE @table table (col1 numeric(16,5))insert into @tableselect 34.0200 union allselect 1232.0560 union allselect 234.4400 union allselect 451232.123 select * from @tablewhere right(str((col1*1000),50 ),1) <>'0' JimEveryday I learn something that somebody else already knew |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-04-22 : 12:56:08
|
| I like Malpashaa's bestDECLARE @table table (col1 numeric(16,5))insert into @tableselect 34.0200 union allselect 1232.0560 union allselect 234.4400 union allselect 451232.123 select * from @table where CAST(CAST(col1 AS DECIMAL(15, 5)) * 1000 AS INT) % 10 <> 0Everyday I learn something that somebody else already knew |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-23 : 03:56:07
|
quote: Originally posted by jimf DECLARE @table table (col1 numeric(16,5))insert into @tableselect 34.0200 union allselect 1232.0560 union allselect 234.4400 union allselect 451232.123 select * from @tablewhere right(str((col1*1000),50 ),1) <>'0' JimEveryday I learn something that somebody else already knew
Beware of rounding This 1232.0508 will be returned by the above queryMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-23 : 03:57:26
|
| Another method isselect * from @tablewhere col1*1000%10>=1MadhivananFailing to plan is Planning to fail |
 |
|
|
pmosca
Starting Member
3 Posts |
Posted - 2010-04-23 : 08:38:18
|
| Thank you everyone...I used webfreds, which worked very nicely for me.thanks!!Pablo MoscaIT ManagerTrinity Stairs, Inc. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-23 : 08:40:34
|
quote: Originally posted by pmosca Thank you everyone...I used webfreds, which worked very nicely for me.thanks!!Pablo MoscaIT ManagerTrinity Stairs, Inc.
Have you seen the previous reply?Did you get any wrong result with that?MadhivananFailing to plan is Planning to fail |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-23 : 08:42:02
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-23 : 08:48:57
|
| [code]select * from @tablewhere FLOOR(col1* 100)!= col1*100[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-23 : 08:51:51
|
quote: Originally posted by visakh16
select * from @tablewhere FLOOR(col1* 100)!= col1*100 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
It falis for the value 1232.05080MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-23 : 08:55:21
|
| [code]select * from @tablewhere col1 NOT LIKE '%.__0%'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-23 : 09:01:09
|
There are too many solutions. Someone with enogh time should test all of them to know which takes less time MadhivananFailing to plan is Planning to fail |
 |
|
|
|