Replace single quotes in transact-sql
If you have single quotes in your text values, and you need to insert them in a SQL Server database the recommended approach is to use parameterized stored procedures. They will handle single quotes seamlessly.
However, there may be cases when you may need to construct an insert statement without resorting to parameters. In such cases, to handle text that contains single quotes you may have to use the Transact-SQL Replace function:
REPLACE ( string_expression , string_pattern , string_replacement )
An example that escapes single quotes by adding another single quote before it:
Declare @temp as varchar(64)
Set @temp= (select … from …)
Set @temp = Replace(@temp, ‘”’,””'’)
In other words, you need 4 single quotes as a second argument, and 6 single quotes as a second argument to escape single quotes.