For what it is worth, Sybase (related to SQL Server) will tolerate both single and double quotes in sql queries. You need to be consistent, though.

I am using Sybase ASE 12.0 and DBD::Sybase to allow users to query a full-text server that joins with another database.

I put my queries into variables and escape any embedded quotes. This permits me to employ nested quotes in certain situations:

$query = "select col_a, col_b, col_c from tablea, tableb where tablea..pkey = tableb..fkey and tablea..column_x = '$fts'";
The $fts string must be enclosed in single quotes, and may contain literals, which need to be enclosed in double quotes:
$fts = "(seedling \<or\> kernel \<or\> embryo) \<and\> \"viab*\" ";
Note that the only time I actually need to escape the quotes are when a double quote is employed within a string variable.

The final form of the query passed to the Sybase server is:

select a,b,c from tablea, tableb
where tablea..pkey = tableb..fkey
and tablea..column_x = '(kernel <or> embryo) <and> "viab*"'

-----
"Computeri non cogitant, ergo non sunt"


In reply to Re: SQL quoting problem by cadfael
in thread SQL quoting problem by lhoward

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.