Selecting all records that....

Discussion in 'Databases - SQL Server 2008 / MySQL' started by boomers, Apr 26, 2007.

  1. boomers CSNM Customer

    Hi

    I have a large table with allot of data in it, Im trying to find the correct SQL statement to select all the records that do not start with a letter or a number.

    So some records may start with a '~' and a few '$' and even some '?'. So I would like a statement that would select all of these while leaving out any records that start with anything else, such as numbers or letters.

    And on a similar theme, Im also trying to select all records that start with a number.

    Ive been using the "select blah from blah where LIKE 'a%'" for each letter and ive tried to have a play and search around that statement, but still not found an answer.

    Would appreciate any help on the matter :)
  2. Ben Collier CSNM Customer

  3. You were along the right lines by using the LIKE command. Try this:

    select * from table where field like '[^a-z]%' and like '[^0-9]%'

    This should return all records that do not start with A-Z or 0-9.

    Hope it helps.

Share This Page