Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace single quotes in SQL Server

I have this function in SQL Server to replace single quotes.

But when I insert a single quote it throws an error on Replace(@strip,''','')):

Create Function [dbo].[fn_stripsingleQuote]     (@strStrip varchar(Max))     returns varchar as begin     declare @CleanString varchar(Max)     SET @var=(Replace(@strip,'',''))      return @var end 
like image 623
acadia Avatar asked Sep 17 '09 19:09

acadia


People also ask

How do you replace a single quote?

Use the String. replace() method to replace single with double quotes, e.g. const replaced = str. replace(/'/g, " ); . The replace method will return a new string where all occurrences of single quotes are replaced with double quotes.

How do you update a quote in SQL?

The short answer is to use two single quotes - '' - in order for an SQL database to store the value as ' .


2 Answers

You need to double up your single quotes as follows:

REPLACE(@strip, '''', '') 
like image 155
David Andres Avatar answered Oct 06 '22 07:10

David Andres


Try REPLACE(@strip,'''','')

SQL uses two quotes to represent one in a string.

like image 45
ScottLenart Avatar answered Oct 06 '22 07:10

ScottLenart