﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server 2005 General Discussion  / isnumeric issue / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 17:23:33 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: isnumeric issue</title><link>http://www.sqlservercentral.com/Forums/Topic936683-149-1.aspx</link><description>Make sure to read this[url]http://www.sqlservercentral.com/articles/IsNumeric/71512/[/url]</description><pubDate>Wed, 01 Dec 2010 01:07:07 GMT</pubDate><dc:creator>Madhivanan-208264</dc:creator></item><item><title>RE: isnumeric issue</title><link>http://www.sqlservercentral.com/Forums/Topic936683-149-1.aspx</link><description>[quote][b]Lowell (6/16/2010)[/b][hr]Steve i made an ITVF based on your example, but i added a bit more to it;i was thinking if i allow periods in the data, i need to check for more than one period...so 123.45 would be valud, but 192.168.1.100 would not;would you agree with that logic?[/quote]Wouldn't just using ISNUMERIC as well as the PATINDEX work in that case? ISNUMERIC will return false for any number with more than one decimal point, because it can't convert that to a valid number!</description><pubDate>Thu, 17 Jun 2010 02:07:52 GMT</pubDate><dc:creator>paul.knibbs</dc:creator></item><item><title>RE: isnumeric issue</title><link>http://www.sqlservercentral.com/Forums/Topic936683-149-1.aspx</link><description>That looks good and definately improves on the logic, nice work.. I guess in the end it depends on the business rules that the OP are running under would determine what is a 'number' or not.</description><pubDate>Wed, 16 Jun 2010 07:58:10 GMT</pubDate><dc:creator>steveb. </dc:creator></item><item><title>RE: isnumeric issue</title><link>http://www.sqlservercentral.com/Forums/Topic936683-149-1.aspx</link><description>Steve i made an ITVF based on your example, but i added a bit more to it;i was thinking if i allow periods in the data, i need to check for more than one period...so 123.45 would be valud, but 192.168.1.100 would not;would you agree with that logic?here's what i put together:[code]CREATE FUNCTION IsNumeric2(@str varchar(20))RETURNS int  WITH SCHEMABINDINGASBEGINdeclare @results intSELECT @results = CASE                 WHEN (PATINDEX('%[^0-9,.]%', @str) = 0) AND (LEN(@str) - LEN(REPLACE(@str,'.','')) &amp;lt;= 1)                THEN 1                ELSE 0              END  return @resultsEND --FUNCTION      GOCREATE FUNCTION IsNumeric3(@str varchar(20))RETURNS TABLE  WITH SCHEMABINDINGASRETURN(SELECT CASE                 WHEN (PATINDEX('%[^0-9,.]%', @str) = 0) AND (LEN(@str) - LEN(REPLACE(@str,'.','')) &amp;lt;= 1)                THEN 1                ELSE 0              END As boolNumeric      ) --END FUNCTION[/code]</description><pubDate>Wed, 16 Jun 2010 07:35:34 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>RE: isnumeric issue</title><link>http://www.sqlservercentral.com/Forums/Topic936683-149-1.aspx</link><description>Thanks Steve for the solution provided. It has worked as expected.Thanks again</description><pubDate>Wed, 16 Jun 2010 06:30:43 GMT</pubDate><dc:creator>ekknaveen</dc:creator></item><item><title>RE: isnumeric issue</title><link>http://www.sqlservercentral.com/Forums/Topic936683-149-1.aspx</link><description>This is because you are passing in a valid money data type so this will return truefrom BOL[quote]ISNUMERIC returns 1 when the input expression evaluates to a valid integer, floating point number, money or decimal type; otherwise it returns 0. A return value of 1 indicates that expression can be converted to at least one of the numeric types.[/quote]I consider ISNUMERIC to be a slightly misleading and possbile dangerous function to use when not fully understood.  It is different than a function that will tell you wheter a value contains only numbers and nothing else.A better what to go about this could be to use PATINDEX, this will only return true where the column contains only Numbers[code]DECLARE @profile CHAR(10)IF PATINDEX('%[^0-9]%', '£123432345') = 0     SET @profile = 'NUMBER'ELSE     SET @profile = 'CHAR'SELECT  @profile[/code]Note:  this is not a pefect example as it will dissallow numbers with a decimal place (.) however you can modify the PATINDEX to meet your business requirements</description><pubDate>Wed, 16 Jun 2010 05:55:14 GMT</pubDate><dc:creator>steveb. </dc:creator></item><item><title>RE: isnumeric issue</title><link>http://www.sqlservercentral.com/Forums/Topic936683-149-1.aspx</link><description>but when I tried to use the below queryIF ISNUMERIC('$123432345')=1 SET @profile = 'NUMBER'ELSE SET @profile = 'CHAR'  SELECT @profileit is also returning number even though its having $ character.Please help</description><pubDate>Wed, 16 Jun 2010 05:37:31 GMT</pubDate><dc:creator>ekknaveen</dc:creator></item><item><title>RE: isnumeric issue</title><link>http://www.sqlservercentral.com/Forums/Topic936683-149-1.aspx</link><description>becasue '2d3'  = 2000 as a valid float value  so ISNUMERIC will return 1[code]SELECT CAST('2d3' AS float)[/code]</description><pubDate>Mon, 14 Jun 2010 03:45:47 GMT</pubDate><dc:creator>steveb. </dc:creator></item><item><title>isnumeric issue</title><link>http://www.sqlservercentral.com/Forums/Topic936683-149-1.aspx</link><description>When I am using the isnumeric function and passing the character value('2d3') its retrrning it as number. Below is the code.DECLARE @profile varchar(200)IF ISNUMERIC('2d3')=1 SET @profile = 'NUMBER'ELSE SET @profile = 'CHAR'  SELECT @profileCan any of  you please tell me why its behaving like this. It should return as CHAR, but returning as NUMBER.Thanks in AdvanceRegards,Naveen</description><pubDate>Mon, 14 Jun 2010 03:38:10 GMT</pubDate><dc:creator>ekknaveen</dc:creator></item></channel></rss>