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 2000 Forums
 Transact-SQL (2000)
 Problem in using LOG10 Function

Author  Topic 

real_pearl
Posting Yak Master

106 Posts

Posted - 2004-10-31 : 23:36:44
Here are the values

declare @MyTable Table(T1 float)
insert into @MyTable
select 5.00E-02 union all
select 5.00E-02 union all
select 0.1 union all
select 0 union all
select 0.15 union all
select 0 union all
select 0.15 union all
select 0.25 union all
select 0 union all
select 5.00E-02 union all
select 0.1 union all
select 0.15 union all
select 0.15 union all
select 0.25 union all
select 0.3 union all
select 0.35 union all
select 0.4 union all
select 0.9 union all
select 1.15 union all
select 1.4 union all
select 1.4 union all
select 1.4 union all
select 0.35 union all
select 0.4 union all
select 0.6 union all
select 0.7 union all
select 0.75 union all
select 0.85 union all
select 1.45 union all
select 1.75 union all
select 1.85 union all
select 1.85 union all
select 2.05 union all
select 5
select T1 from @MyTable
select LOG10(ABS(T1)) T1 from @MyTable


When I run select query without using Log10 function ut returns me 34 rows but when I use Log10 function, the query returns 3 rows. How can I get the same number of rows even using Log10 function. While if you use log10 function on the individual value it returns some value e.g.,

select LOG10(ABS(1.85))

Please tell me how to solve this issue

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2004-11-01 : 03:17:06
You'd have to prevent the domain error that will occur for the rows that have 0.0 in them:

select CASE WHEN T1 = 0.0 THEN NULL ELSE LOG10(ABS(T1)) END T1 from @MyTable

Though I'm not really clear what why you want positive and negative values to give the same result. Perhaps you should decide on some smallest possible value and use LOG10(T1-@smallestPossibleValue+@epsilon) so the parameter of the LOG10 function is always positive.
Go to Top of Page

real_pearl
Posting Yak Master

106 Posts

Posted - 2004-11-01 : 04:42:21
Thanks Arnold, I utimately did the similar.
Go to Top of Page
   

- Advertisement -