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 2012 Forums
 Transact-SQL (2012)
 Removing Data that has alpha letters

Author  Topic 

hbadministrator
Posting Yak Master

120 Posts

Posted - 2013-01-17 : 14:25:35
I have a field that has data with numbers that can very from 3 chars to 8 chars and some have letters in them. I want to eliminate that data from my selections.

example data
Field Name
ccode
1000
1000f
1002
1004f
12321412g
21334123h
1234512f


what is my WHERE statement

WHERE ccode....


Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-01-17 : 16:00:03
[code]DECLARE @Foo TABLE (Col VARCHAR(10))
INSERT @Foo
VALUES
('ccode'),
('1000'),
('1000f'),
('1002'),
('1004f'),
('12321412g'),
('21334123h'),
('1234512f')

-- NO values with a-z
SELECT *
FROM @Foo
WHERE Col NOT LIKE '%[a-z]%'

--OR, olny values that are 0-9
SELECT *
FROM @Foo
WHERE Col NOT LIKE '%[^0-9]%'
[/code]
Go to Top of Page
   

- Advertisement -