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
 General SQL Server Forums
 New to SQL Server Programming
 isnumeric issue

Author  Topic 

Sean_B
Posting Yak Master

111 Posts

Posted - 2007-08-28 : 11:06:10
Hi,

I'm casting a varchar field to a decimal field using the format

CASE ISNUMERIC(GrossMktCapGbp)
WHEN 1 THEN CONVERT(DECIMAL(18,6),GrossMktCapGbp)
ELSE NULL
end

Thinking this would ensure that any spurious rows got set to null.

However I had a problem with some values that were set to '.', it seems that isnumeric thinks these are numbers but casting them to decimal produces an error.

SELECT ISNUMERIC('.')
SELECT CAST('.' AS DECIMAL(18,6))

Should I have been doing something different in my check possibly.




Sean

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-28 : 11:11:43
isNumeric is a bit odd...
use like like this simple example
where GrossMktCapGbp not like '%[a-z]%'

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-28 : 11:12:16
Do you any negative number?
If not, just add a ZERO before.

SELECT ISNUMERIC('0' + '.')
SELECT ISNUMERIC('0' + '12.23')
SELECT ISNUMERIC('0' + '.23')
SELECT ISNUMERIC('0' + '0.23')
SELECT ISNUMERIC('0' + '234')




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-28 : 11:14:28
[code]CASE
WHEN GrossMktCapGbp = '.' THEN <some default value for dot only here>
WHEN ISNUMERIC(GrossMktCapGbp) = 1 THEN CONVERT(DECIMAL(18,6), GrossMktCapGbp)
ELSE <some default value for non-numeric value here>
END[/code]

E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Sean_B
Posting Yak Master

111 Posts

Posted - 2007-08-28 : 11:20:07
Thanks guys.

Sean
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-28 : 12:17:30
New Style


CASE ISNUMERIC(GrossMktCapGbp+'d0')
WHEN 1 THEN CONVERT(DECIMAL(18,6),GrossMktCapGbp)
ELSE NULL
end


Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2007-08-29 : 06:23:34
See also: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=59049&SearchTerms=isnumeric

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-29 : 07:13:18
quote:
Originally posted by Kristen

See also: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=59049&SearchTerms=isnumeric

Kristen


Welcome back Kristen

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2007-08-29 : 08:51:12
"Welcome back Kristen"

Been doing some gardening ... changing the shape of the pond and widening the drive ...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-29 : 09:00:14
quote:
Originally posted by Kristen

"Welcome back Kristen"

Been doing some gardening ... changing the shape of the pond and widening the drive ...


I hope you TESTed it well

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2007-08-29 : 09:04:37
Not all that well .. went through the Water, Electric and Phones . However I now know where they all are
Go to Top of Page
   

- Advertisement -