Unix Technical Forum

single quote

This is a discussion on single quote within the SQL Server forums, part of the Microsoft SQL Server category; --> How do I insert a single quote ' into a table? For example: Insert mytable values (1,''') I get ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 11:33 AM
othellomy@yahoo.com
 
Posts: n/a
Default single quote

How do I insert a single quote ' into a table? For example:
Insert mytable values (1,''')
I get an error message.

Any ideas? The server does not recognize double quote (why? is this
tsql, ansi?), otherwise I could have written it as:
Insert mytable values (1,"'")

Thanks.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 11:33 AM
othellomy@yahoo.com
 
Posts: n/a
Default Re: single quote

Nevermind. Following worked:
SET QUOTED_IDENTIFIER OFF
insert mytable values (3,"'",getdate())

othell...@yahoo.com wrote:
> How do I insert a single quote ' into a table? For example:
> Insert mytable values (1,''')
> I get an error message.
>
> Any ideas? The server does not recognize double quote (why? is this
> tsql, ansi?), otherwise I could have written it as:
> Insert mytable values (1,"'")
>
> Thanks.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 11:33 AM
Erland Sommarskog
 
Posts: n/a
Default Re: single quote

(othellomy@yahoo.com) writes:
> Nevermind. Following worked:
> SET QUOTED_IDENTIFIER OFF
> insert mytable values (3,"'",getdate())



Yes, that's one way to do it. But it will not always work, because the
setting QUOTED_IDENTIFIER must be ON in some situations.

The standard way to do it is do double the string delimiter:

insert mytable values (3, '''', getdate())

Standard SQL only recognizes ' as a string delimiter. " is used to delimiter
identifiers with "funny" characters in them, like space. (Although with SQL
Server you normally use [] in this case.)

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 11:33 AM
Dan Guzman
 
Posts: n/a
Default Re: single quote

To add on to Eland's response, the ANSI standard QUOTED IDENTIFIER ON allows
you to use SQL Server features line indexes on views and computed columns.

--
Hope this helps.

Dan Guzman
SQL Server MVP

<othellomy@yahoo.com> wrote in message
news:1163056886.515598.327620@h48g2000cwc.googlegr oups.com...
> Nevermind. Following worked:
> SET QUOTED_IDENTIFIER OFF
> insert mytable values (3,"'",getdate())
>
> othell...@yahoo.com wrote:
>> How do I insert a single quote ' into a table? For example:
>> Insert mytable values (1,''')
>> I get an error message.
>>
>> Any ideas? The server does not recognize double quote (why? is this
>> tsql, ansi?), otherwise I could have written it as:
>> Insert mytable values (1,"'")
>>
>> Thanks.

>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-01-2008, 11:33 AM
Erland Sommarskog
 
Posts: n/a
Default Re: single quote

Dan Guzman (guzmanda@nospam-online.sbcglobal.net) writes:
> To add on to Eland's response, the ANSI standard QUOTED IDENTIFIER ON
> allows you to use SQL Server features line indexes on views and computed
> columns.


And in SQL 2005, XQuery.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:30 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com