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 2005 Forums
 Transact-SQL (2005)
 Case when not working

Author  Topic 

NeilG
Aged Yak Warrior

530 Posts

Posted - 2010-09-06 : 06:54:33
Hi Guys,

Hoping someone can spot something I can't, I'm trying to return some data from a table holding information on Books. But in the startpage somepeople have not entered data or text instead of a value, because I'm trying to use this column for a calculation I thought I'd use a case when to convert it to INT where its numeric else leave as it is.


SELECT
CASE WHEN ISNUMERIC(StartPage) = 0 THEN StartPage ELSE CONVERT(INT,StartPage ) END,
ISNUMERIC(StartPage)
FROM
books (Nolock)
WHERE
ID = 852695

However when I run this query it displays an error saying it can't change "i" into INT datatype, that's fine but the ISNUMERIC(StartPage) = 0 clause returns 0 so it shouldn't attempt to convert that value.

Where am I going wrong.

-----------------------------------------------
Learning something new on SQL Server everyday.

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-09-06 : 07:07:28
ISNUMERIC() is not trustful

have a look on

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/enhanced-isnumeric-function.aspx



Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2010-09-06 : 07:12:39
Excellent Thanks

-----------------------------------------------
Learning something new on SQL Server everyday.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-09-06 : 07:14:46
quote:
Originally posted by NeilG

Excellent Thanks

-----------------------------------------------
Learning something new on SQL Server everyday.



Welcome

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -