Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 Article Discussion
 Article: Apostrophe's and Quotation Marks in SQL Server

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-08-07 : 14:23:53
DJM writes "How do I deal with a variable in a query that may or may not contain an apostrophe, such as "d'Arby"? My SQL runs fine until it hits such an entry, and then of course stops cold, thinking the value is "d", leaving some unknown bogus command called "Arby'". I've given myself migraines over this. I would appreciate it no end if you could help me out of this dilemna. I'm using ASP on IIS with Transact SQL." This Ask SQLTeam has been updated with some additional information on apostraphe's since this seems to be a very popular question.

Article Link.

wevans
Starting Member

1 Post

Posted - 2002-11-25 : 01:26:00
I actually think the best way on both inserts and subsequent queries against the data is to use Chr(146).

Something like this:

Replace(Request.Form("DaInBox"),"'",Chr(146))

Go to Top of Page

sqlMichael
Starting Member

1 Post

Posted - 2009-10-23 : 17:44:32
I've creaetd a sProc that uses the QUOTENAME function, it runs fine in SQL Server 2005, but when I add the sProc to a reporting service, the output file now has triple the amount of quotes I was expecting.
EXMAMPLE:
Query returns "NAME"
Using a subscription service, the output is now """NAME"""
I've setup the subscription to output with as a comma delimited CSV file.

Query is setup as
Select
'Client Name' = QUOTENAME(CLNAME,'"')
From TABLE

Is the triple quotes a result of the use of QUOTENAME, or a result of the reporting service?
Sorry if this topic should be posted under a differnt area. It's my first post.

sglmichael
Go to Top of Page
   

- Advertisement -