Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 [RESOLVED] parse numeric value

Author  Topic 

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2011-02-17 : 10:37:26
I have a column with numeric values (23.0123456789).
I would like to parse this number to find out if the 3 decimal is greater than '0'. How would I approach this?

Thanks for your help.

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-17 : 10:52:49
select (case when cast(substring(CAST(ColumnName as varchar(15)),CHARINDEX('.',reverse(CAST(ColumnName as varchar(15))))-4,1) AS tinyint)>3 then 'Yes' else 'No' end) as GreaterOrNot
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-02-17 : 10:59:42
Or:

SELECT CASE WHEN CAST(ColumnName * 1000 % 10 as int) > 0 THEN 'Yes' ELSE 'No' END FROM myTable
Go to Top of Page

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2011-02-17 : 11:22:44
Fantastic - thanks!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-18 : 10:30:54
or

1
select case when data like '%.[0-9][0-9][1-9]%' then 'yes' else 'no' end FROM myTable

2
select case when data like '%.__[1-9]%' then 'yes' else 'no' end FROM myTable


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -