How do I escape a single quote in SQL Server

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I m trying to insert some text data into a table in SQL Server 9.

The text includes a single quote.

How do I escape that?

I tried using two single quotes, but it threw me some errors.

eg. insert into my_table values( hi, my name s tim. );

Answers

  Single quotes are escaped by doubling them up   , just as you ve shown us in your example. The following SQL illustrates this functionality. I tested it on SQL Server 2008:
DECLARE @my_table TABLE (
    [value] VARCHAR(200)
)

INSERT INTO @my_table VALUES ( hi, my name  s tim. )

SELECT * FROM @my_table

Results

value
==================
hi, my name s tim.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/1586560/how-do-i-escape-a-single-quote-in-sql-server

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils