The ' (single quote or apostrophe) is a string delimiter.  In MySQL
the ` (backtick) is used to escape names that are also keywords.  The
MS products use [brackets] for the task.  I believe the standard way
to escape is with " (double quotes).  MySQL supports this syntax, and
I believe the MS products do too.  MySQL also supports using " (double
quotes) for string delimiters.  I don't know about the MS products,
but I'd be surprised if they didn't.  I believe Access forces you to
use " (double quote) rather than ' (single quote) when you're using
the actual Access program, but if you're connecting via ODBC the
restriction is not enforced.  Finally, I don't believe MS products use
the ` (backtick) for anything, but I could be wrong.

Assuming a table with the proper structure, this would be a legal
statement in MySQL, illustrating both keyword escapes.

SELECT `group`, SUM(age) AS "count"
FROM myTable
GROUP BY `group`

In MS SQL, you' d use brackets like this, instead of backticks:

SELECT [group], SUM(age) AS "count"
FROM myTable
GROUP BY [group]

In both cases, the decision to use " (double quotes) for the "count"
keyword was complete arbitrary, it could have used the
backtick/bracket escapes just as well.  Note that a table.column
reference is two identifiers, not one, so you'd escape it like this:
"table"."column", not like this "table.column".

So to make your SQL as general as possible, use ' (single quote) for
strings (which I haven't demonstrated anywhere), and " (double quote)
for keyword escapes.  If you do that, it'll run on either platform as
far as I know.

cheers,
barneyb

On Mon, 31 Jan 2005 21:38:19 -0600, Nick Baker <[EMAIL PROTECTED]> wrote:
> What is the story with the characters ` and ' in SQL and the like ? I have
> never been able to find anything that gives some reasoning behind the
> logic. Seems like the ` is used a little differently in MS Access, MySQL
> and MS SQL? While the ' seems to be used to denote text or string for data.
> 
> Thanks,
> 

-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 6 invites.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:192509
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to