|
I have a table of about 90K records. One of the fields is nvarchar(20) and should only contain NUMBERS. However some contain an alpha mix. Can someone suggest a quick way to identify the records that have LETTERS imbedded in the string? Thanks, John
(comments are locked)
|
|
Use PATINDEX to search for letters
assuming it is case-insenstive, otherwise
If the requirement is twisted somewhat to say ONLY numbers are allowed, then
As mentioned in the comment to another answer, ISNUMERIC will return true if the string can be converted to a numeric data type (which includes float, real and money). Because of this, some non-number characters are acceptable '+', '-', 'd', 'e', and currency symbols e.g. '$', '£' The last query will select all rows that contain only numbers - because you're saying NOT like and also using the ^ excluder in the pattern. Also, i'd be interested to see whether patindex('[a-zA-Z]', myColumn) might be more efficient than lower(myColumn)?
Oct 21 '09 at 11:53 AM
Matt Whitfield ♦♦
oops! cheers for spotting that Matt, fixed now!
Oct 21 '09 at 12:27 PM
Kev Riley ♦♦
(comments are locked)
|
This will probably use a table scan because of the function on field, but with only 90k records, it shouldn't be a problem Be careful with ISNUMERIC. Try
Oct 21 '09 at 09:15 AM
Kev Riley ♦♦
(comments are locked)
|
|
Since only letters need to be identified:
(comments are locked)
|


Excellent answers all and thanks for the very quick response.
John, have you thought about accepting one of the answers as your 'Accepted Answer'? It will help others in future.