Search code examples
c#sqlms-accessselectoledb

SQL Select String with Keyword


So lets say I had a db table, Errors

 [ID]    [ErrorDescription]
   1     "SELECT Name LIKE '*A*' Returned 0 Results"
   2     "SELECT Returned Multiple Results"

And I wanted to run a query like

SELECT ID 
FROM Errors 
WHERE ErrorDescription = 'SELECT Name LIKE '*A*' Returned 0 Results'

Is there a way to make this work? Currently I'm getting an

OLEDB Exception "Syntax Error (missing operator) in query expression"

when I'm trying to use an OleDbDataAdapter to run the query on an MS Access file. I looked around and couldn't find anything related to this, lots on using square brackets for keyword column names but not my particular issue.


Solution

  • Have to escape the single-quotes, otherwise you're confusing the parser:

    SELECT ID FROM Errors WHERE ErrorDescription ='SELECT Name LIKE ''*A*'' Returned 0 Results'