This is a bit theoretical answer, but maybe it will help. The short version is "using parameters in a query", but it helps to understand all the details.
In standard SQL, strings are enclosed in single quotes, and embedded single quotes are represented by two single quotes in a string:
SELECT * FROM SomeWhere WHERE SomeThing = 'He said, "Don''t do it!"';
In some dialects of SQL, you can instead close double-quoted strings; you need to double double quotes to insert one instance of double quotes:
SELECT * FROM SomeWhere WHERE SomeThing = "He said, ""Don't do it!""';
It is unclear whether the company name refers to external double quotes, as well as to the middle, or simply contains the middle. However, in principle, the rules are the same. Assuming all three double quotes are necessary, and using single quotes in SQL is much simpler in this context:
SELECT c.companyID, c.companyName, c.dateAdded, count(cm.maxID) as NumDirect FROM RussoundGeneral.dbo.Company c LEFT JOIN RussoundGeneral.dbo.CompanyMax cm ON (cm.companyId = c.companyId and cm.maxID is not null) WHERE CONTAINS ( companyName, '"BLAH "BLAHBLAH" Ltd.' ) GROUP BY c.companyID, c.companyName, c.dateAdded ORDER BY c.companyName ASC;
Using double quotes:
SELECT c.companyID, c.companyName, c.dateAdded, count(cm.maxID) as NumDirect FROM RussoundGeneral.dbo.Company c LEFT JOIN RussoundGeneral.dbo.CompanyMax cm ON (cm.companyId = c.companyId and cm.maxID is not null) WHERE CONTAINS ( companyName, """BLAH ""BLAHBLAH"" Ltd." ) GROUP BY c.companyID, c.companyName, c.dateAdded ORDER BY c.companyName ASC;
If you are building strings in a programming language, you have to worry about getting these quotes for everything that evaluates strings in your programming language. For example, if you were building a string literal in C, you would need to avoid double quotes with backslashes:
static const char sql_stmt[] = "SELECT c.companyID, c.companyName, c.dateAdded,\n" " COUNT(cm.maxID) AS NumDirect\n" " FROM RussoundGeneral.dbo.Company c\n" " LEFT JOIN RussoundGeneral.dbo.CompanyMax cm\n" " ON (cm.companyId = c.companyId AND cm.maxID IS NOT NULL)\n" " WHERE CONTAINS(companyName, \"\"\"BLAH \"\"BLAHBLAH\"\" Ltd.\")\n" " GROUP BY c.companyID, c.companyName, c.dateAdded\n" " ORDER BY c.companyName ASC";
On the other hand, if you are reading data from a user - for example, the name of the company, then you just need to make sure that what you read is correctly indicated.
Those who said "use parameters" are correct - it is much simpler and more reliable and less vulnerable to SQL injection (see XKCD if you still do not see this). But if you understand the basics, you can adapt to the real requirements of your system.
Final note: in standard SQL, double quotation marks enclose "separable identifiers." That is, double quotes surround the name, which should be considered as the name of something in the database, and not as a string literal. In MS SQL Server, [square brackets] serve the same purpose; what is between the brackets is the name of the column or something inside the database. Many systems are more flexible than this; not all systems are the same in how they deviate from the standard.