Is there an equivalent of PostgreSQL's Dollar-quoted String Constants, on SQL Server?
I would like to enter HTML string literals that would potentially contain single or double quotes in them.
Example:
UPDATE table_name
SET column_name = $$
Here's a string that contains "double quotes".
$$
WHERE condition = true
Edit:
The reason I'm asking this is because I would like to update some rather big HTML "web parts" that are stored in the database (yuck!). Because at work we use that kind of CMS (which I won't give you the name). So I don't want to have to escape my single quotes every time. That's why I'm asking about that kind of feature. If I understand correctly, QUOTENAME
would still require me to double my single quotes.
Best Answer
This is a PostgreSQL extension of the spec. There is nothing like it in SQL Server. The idea is that you can quote everything that doesn't have the
$$[token]$$
. If the optionaltoken
is absent it looks like$$
. Thus the name, Dollar-quoted String ConstantsSo you can pass something like this,
or, even this.
And we do that frequently with modules like
tablefunc
As a workaround, in SQL Server, you just have to be escape the single quotes and double escape the single-quotes in the single quotes. This is the standard method of literal-quoting.
The
''''
is what we're trying to avoid here. That's fugly.