-
SQL help required!
If anyone is a SQL guru then you may be able to help me out. I'm trying to write a SQL query to return IP addresses in the range '10.1.*' - that is, any IP addresses that begin with '10.1.' followed by anything.
However, I believe that entering '10.1.*' as the search criteria in my SQL query will interpret the '.*' as a wildcard rather than taking the '.' before the '*' as a literal character.
So, what should my search string be to take the second '.' as a literal character followed by any characters
-
Which version of sql are you using?
I only know oracle sql I'm afraid, and neither . or * is a wildcard as far as I know.
The wildcard characters are _ (to match single character) and % (to match multiple characters).
so you would want something like:
where ip like '10.1.%'
or alternativley you could avoid wildcards altogether by using something like:
where substr(ip,1,5) = '10.1.'
-
It's a query into MS SQL Server 2000. I think you're right though. I'll use '%' instead of '*'.
-
Can you put a \ in front of the . to have SQL take it literly. I know I have to do that for quotes.
-
You also need to use the Keyword "Like". So...
Code:
where ipAddress like '10.10.%'