How to delete records in SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sc5502
    New Member
    • Jun 2014
    • 102

    How to delete records in SQL

    Front end - MS Access 2010 / VBA
    Back End - MS SQL Server 2008

    I have a SQL table that is not related to any other table. It is defined as:

    ID int
    FIELD1 varchar(50)
    FIELD2 varchar(50)
    FIELD3 varchar(50)

    Field 1 contains an alpha value concatenated with numbers. An example: AAAAA0021. Below is a typical
    table.

    1 AAAA5555 W AAAAAAAA
    2 BBBB3312 W BBBBBBBB
    3 CCCC5423 W DDDBBBB
    4 AAAA3189 R CCCCCCCC
    5 AAAA6500 R AAAAAAAA
    6 EEEE34AS W EEEEEEEEEE

    I want to delete all records where Field1 begins with AAAA. Below is what the table will look like when
    the delete completes:

    2 BBBB3312 W BBBBBBBB
    3 CCCC5423 W DDDBBBB
    6 EEEE34AS W EEEEEEEEEE


    How can I accomplish this? Thanks in advanced.
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    You can use the Like Operator. If the Table is Linked:
    Code:
    dbCurrent.Execute "DELETE FROM SomeTable WHERE Field1 LIKE 'AAAAA*'", dbFailOnError + dbSeeChanges

    Comment

    • sc5502
      New Member
      • Jun 2014
      • 102

      #3
      It works. Thank you.

      Comment

      Working...