I recently got a comment on that article from a sqlservercurry.com visitor who asked me to find out if a string has numbers, using PatIndex. Here's how to do so using PatIndex :
DECLARE @str1 varchar(15)
SET @str1 = 'abcde99jtk'
-- Check if PatIndex returns a value > 0. If yes, the string has numbers
-- If the value is 0, the string does not have numbers
IF PATINDEX('%[0-9]%',@str1) > 0
PRINT 'YES, The string has numbers'
ELSE
PRINT 'NO, The string does not have numbers'
Did you like this post?
|
|
|
||
|
|
|
|
|
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |




comments
2 Responses to "How to check if a string contains numbers"Awesome, thanks for the post! solved it!
thanks a lot, this query helped me with a related problem...
Post a Comment