Sunday, February 19, 2012

How to query for a number only?

I have a varchar column, I want to find the records where the value is a
number only.
TIA
CDSee if this helps:
What is wrong with IsNumeric()?
http://www.aspfaq.com/show.asp?id=2390
AMB
"CD" wrote:

> I have a varchar column, I want to find the records where the value is a
> number only.
> TIA
> CD
>
>|||Hi
just see if this helps:
SELECT *
FROM <table>
WHERE ISNUMERIC(<Column> ) = 1
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
---
"CD" wrote:

> I have a varchar column, I want to find the records where the value is a
> number only.
> TIA
> CD
>
>|||CD
CREATE TABLE #Test
(
col VARCHAR(10) NOT NULL
)
INSERT INTO #Test VALUES ('GDGS12')
INSERT INTO #Test VALUES ('566')
INSERT INTO #Test VALUES ('GGG')
SELECT * FROM #Test WHERE PATINDEX('%[A-Z]%',col) =0
"CD" <mcdye1@.hotmail.REMOVETHIS.com> wrote in message
news:ONdeU2CbFHA.3120@.TK2MSFTNGP12.phx.gbl...
> I have a varchar column, I want to find the records where the value is a
> number only.
> TIA
> CD
>|||Here's a UDF that checks if a value is really numeric.
Sorry, I don't remember who to give credit to for the function.
CREATE FUNCTION dbo.IsReallyNumeric
(@.num VARCHAR(19))
RETURNS BIT
BEGIN
RETURN CASE
WHEN LEFT(@.num,1) LIKE '[-0-9+.]'
AND PATINDEX('%[^0-9.]%', SUBSTRING(@.num, 2, 18)) = 0
AND LEN(@.num) - LEN(REPLACE(@.num, '.', '')) <=1
THEN 1
ELSE 0
END
END
"CD" <mcdye1@.hotmail.REMOVETHIS.com> wrote in message
news:ONdeU2CbFHA.3120@.TK2MSFTNGP12.phx.gbl...
>I have a varchar column, I want to find the records where the value is a
>number only.
> TIA
> CD
>

No comments:

Post a Comment