Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.databases.ms-sqlserver > #318
| From | "Bob Barrows" <reb01501@NOyahooSPAM.com> |
|---|---|
| Newsgroups | comp.databases.ms-sqlserver |
| Subject | Re: Fred. (ghrno-google@yahoo.com) writes:isnumeric has always been useless. |
| Date | 2011-05-10 14:56 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <iqc32k$t3s$1@dont-email.me> (permalink) |
| References | <Xns9ED171C6FB504Yazorman@127.0.0.1> <2011510141922usenet@terrranews.com> |
Pedro Eu wrote:
> Fred, I'm trying to use your solution but I think something is going
It wasn't Fred's solution, it was Erland's suggestion.
> wrong. Try this:
>
<snip>
> IF '123' LIKE '%[^0-9]%'
> BEGIN
> PRINT '3rd case OK'
> END
>
> IF '123a' LIKE '%[^0-9]%'
> BEGIN
> PRINT '4th case OK'
> END
>
> Sql Server result:
> 1st case OK
> 4th case OK
>
> The 1st case is ok to me, but I do not understood why the 3rd case is
> not ok and the 4th is.
>
> Any idea?
Yes. You did not follow the suggested solution. Specifically, you left out
the "NOT" keyword:
IF '123' NOT LIKE '%[^0-9]%'
PRINT '''123'' contains only numeric characters'
ELSE
PRINT '''123'' contains at least one non-numeric character'
and
IF '123a' NOT LIKE '%[^0-9]%'
PRINT '''123a'' contains only numeric characters'
ELSE
PRINT '''123a'' contains at least one non-numeric character'
The pattern [^0-9] means "not 0 to 9", so the expression LIKE '%[^0-9]%'
returns true if any characters that are not 0 to 9 are found in the string.
Does that help?
<snip>
>>> On Sunday, April 24, 2011 5:11 AM Erland Sommarskog wrote:
>
>>> Fred. (ghrno-google@yahoo.com) writes:
>>>
>>> isnumeric has always been useless.
>>>
>>> If you need to validate for unsigned integers, you can use this
>>> expression:
>>>
>>> col NOT LIKE '%[^0-9]%'
>>>
>>> This expression returns false, as soon there is a value which
>>> contains any non-digit character including space.
>>>
Back to comp.databases.ms-sqlserver | Previous | Next — Previous in thread | Next in thread | Find similar
Looking for faster integer validation "Fred." <ghrno-google@yahoo.com> - 2011-04-23 15:02 -0700
Re: Looking for faster integer validation Erland Sommarskog <esquel@sommarskog.se> - 2011-04-24 11:11 +0200
Re: Fred. (ghrno-google@yahoo.com) writes:isnumeric has always been useless. Pedro Eu <pedro.wtf@gmail.com> - 2011-05-10 18:19 +0000
Re: Fred. (ghrno-google@yahoo.com) writes:isnumeric has always been useless. Gene Wirchenko <genew@ocis.net> - 2011-05-10 12:01 -0700
Re: Fred. (ghrno-google@yahoo.com) writes:isnumeric has always been useless. "Bob Barrows" <reb01501@NOyahooSPAM.com> - 2011-05-10 14:56 -0400
Re: Fred. (ghrno-google@yahoo.com) writes:isnumeric has always been useless. "Fred." <ghrno-google@yahoo.com> - 2011-05-10 12:20 -0700
Re: Fred. (ghrno-google@yahoo.com) writes:isnumeric has always been useless. "Fred." <ghrno-google@yahoo.com> - 2011-05-10 12:50 -0700
csiph-web