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
 Analysis Server and Reporting Services (2005)
 Query help

Author  Topic 

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-03-06 : 06:48:59
Hi,

If i wanted to return rows where the field in them only has numbers how would I go about doing that?

for instance in access:
WHERE Field like '#'

which is the wildcard, is there equivalent in sql?

Ifor
Aged Yak Warrior

700 Posts

Posted - 2009-03-06 : 07:02:18
[code]WHERE YourColumn NOT LIKE '%[^0-9]%'[/code]
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-03-06 : 07:03:13
If you want it limit to only NUMBERS ONLY (as in characters 0 to 9 - no decimals - no commas - no spaces then

DECLARE @bar TABLE (
[foo] VARCHAR(50)
)

INSERT @bar
SELECT '1'
UNION SELECT '10.1'
UNION SELECT 'foo'
UNION SELECT 'foo 1'
UNION SELECT '435'

SELECT
foo
FROM
@bar
WHERE
foo NOT LIKE '%[^0-9]%'

There is an ISNUMERIC function but it frequently gets things wrong.

If that isn't enough then post some sample data and expected results.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-07 : 13:57:11
also see

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/enhanced-isnumeric-function.aspx
Go to Top of Page
   

- Advertisement -