dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: sql syntax error

  1. #1
    Join Date
    Aug 2002
    Location
    germany
    Posts
    83

    sql syntax error

    hi,
    I need to use the ' character in my sql text, but v.b. will see this as an error, how can i use this character? I am doing a like query....

    my sqltext is as follows

    SELECT fname, lname, solfname, sollname, AccidentID FROM Accident WHERE lname LIKE 'o'*'


    the ' character is a valid character in my database, but i keep getting the error syntax error... please help if you can...
    these computers are making me drink beer!!!!!

  2. #2
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    Simply use ''

    SELECT fname, lname, solfname, sollname, AccidentID FROM Accident WHERE lname LIKE 'o''*'

    Access like SQL server will treat repeated ' or " characters as "escaped" ie only one will be seen by the statement.

    This is a useful trick to ensure that you can use statements like

    Insert Into Names Values('O''Reilly')

    And get O'Reilly stored in the table.
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)