SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Single Quotation Marks in SQL


Single Quotation Marks in SQL

Author
Message
Nemeaux
Nemeaux
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 166
Although the overall technical correctness of this article is good there is a glaring error in the narrative. There is no such thing as a "single quote" mark. There is an apostrophe mark and there is a quotation mark. A single quote looks thusly " and a double quote looks this way "". What the article’s author refers to as a "single quote" is in reality an apostrophe mark ' and what is referred to as a "double quote" is actually a quotation mark.

I bring this up because the difference is really quite significant. Calling an apostrophe a "single quote" is, putting it simply, quite wrong. It would be like calling a “V” a single “W” and calling a “W” a “double W”.

When looking up "quotation marks" in the Oxford Online Dictionary, http://oxforddictionaries.com/words/punctuation, I see no punctuation mark labeled as "single quote". Nor is there a mention of a "double quote".

Yes, I'm tilting windmills. But one must try occasionally, mustn't one?

Thanks for the soapbox.
Kenneth.Fisher
Kenneth.Fisher
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4360 Visits: 2033
Nemeaux (1/3/2013)
Although the overall technical correctness of this article is good there is a glaring error in the narrative. There is no such thing as a "single quote" mark. There is an apostrophe mark and there is a quotation mark. A single quote looks thusly " and a double quote looks this way "". What the article’s author refers to as a "single quote" is in reality an apostrophe mark ' and what is referred to as a "double quote" is actually a quotation mark.

I bring this up because the difference is really quite significant. Calling an apostrophe a "single quote" is, putting it simply, quite wrong. It would be like calling a “V” a single “W” and calling a “W” a “double W”.

When looking up "quotation marks" in the Oxford Online Dictionary, http://oxforddictionaries.com/words/punctuation, I see no punctuation mark labeled as "single quote". Nor is there a mention of a "double quote".

Yes, I'm tilting windmills. But one must try occasionally, mustn't one?

Thanks for the soapbox.


Actually I appreciate the feedback. One of my biggest problems with writing, be it a blog entry, a QotD or an article like this one is that I have a tendency to use "common usage" phrases. I forget that these can be very difficult for someone who isn't fluent in English or for that matter learned it using different idioms than I'm used to.

In my own defense though you will find them described as single and double quotation marks in BOL. I checked when I was writing the article Cool.

Kenneth Fisher
I strive to live in a world where a chicken can cross the road without being questioned about its motives.
--------------------------------------------------------------------------------
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Link to my Blog Post --> www.SQLStudies.com
Nemeaux
Nemeaux
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 166
Ah, if only we could now get BOL to see the light!

In any case, good article...keep up the good writing!

Dave
sknox
sknox
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2669 Visits: 2833
roger.plowman (1/3/2013)
This issue is yet another example of why SQL is one of the worst-designed languages of all time from a syntactic POV.

Would it have killed the designers to create two string delimiters that could be interchanged (ala BASIC) and reserved square brackets for field/table delimiting?

So that when you have a string which contains both delimiters as literals, you have double the problem? Syntactically, having two delimiters that mean the same thing is a problem, not a solution.

And while we're at it to use #'s to delimit dates/times (ala MS Access)?

"ala MS Access" == NO. Besides, there's plenty of good documentation on date formatting in SQL, and simply changing 's to #s wouldn't give you any better conversion rate.

Oh, and use a dedicated "escape" character instead of doubling the escaped character? Sheesh!

On this one, I agree with you -- in principle at least. From a syntax standpoint, it makes sense to have a specific escape character, like regular expressions do, for example. But what happens when you need to include the escape character as a literal? Double the escaped character, again.

In the case of T-SQL and string literals, the only character which would ever need to be escaped is '. So the options were:

a) create an escape character (let's say \) and then use that character to escape every literal ' and \ (i.e, have possible two escape clauses: \' and \\), or

b) use ' as the escape character for itself and have one possible escape clause ('').

So they again opted for the simpler solution.
Kenneth.Fisher
Kenneth.Fisher
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4360 Visits: 2033
sknox (1/3/2013)
roger.plowman (1/3/2013)
This issue is yet another example of why SQL is one of the worst-designed languages of all time from a syntactic POV.

Would it have killed the designers to create two string delimiters that could be interchanged (ala BASIC) and reserved square brackets for field/table delimiting?

So that when you have a string which contains both delimiters as literals, you have double the problem? Syntactically, having two delimiters that mean the same thing is a problem, not a solution.

And while we're at it to use #'s to delimit dates/times (ala MS Access)?

"ala MS Access" == NO. Besides, there's plenty of good documentation on date formatting in SQL, and simply changing 's to #s wouldn't give you any better conversion rate.

Oh, and use a dedicated "escape" character instead of doubling the escaped character? Sheesh!

On this one, I agree with you -- in principle at least. From a syntax standpoint, it makes sense to have a specific escape character, like regular expressions do, for example. But what happens when you need to include the escape character as a literal? Double the escaped character, again.

In the case of T-SQL and string literals, the only character which would ever need to be escaped is '. So the options were:

a) create an escape character (let's say \) and then use that character to escape every literal ' and \ (i.e, have possible two escape clauses: \' and \\), or

b) use ' as the escape character for itself and have one possible escape clause ('').

So they again opted for the simpler solution.


I do see one benefit for using an escape character that isn't your delimiter. '\\' is quite a bit easier to follow than ''''. Or for that mater '\\\\' is much easier than ''''''. On the whole though I agree with you. A character had to be picked as an escape character and regardless of what character it was we were going to have some level of problems with it.

Kenneth Fisher
I strive to live in a world where a chicken can cross the road without being questioned about its motives.
--------------------------------------------------------------------------------
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Link to my Blog Post --> www.SQLStudies.com
Patel.darsan
Patel.darsan
SSC-Enthusiastic
SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)

Group: General Forum Members
Points: 129 Visits: 114
nice article. thanks.

DECLARE @topsql NVARCHAR(200)

SET @topsql = 'DECLARE @quotedvar nvarchar(100) ' + CHAR(13)
+ 'DECLARE @sql nvarchar(1000) ' + CHAR(13)
+ 'SET @quotedvar = ''O''''Neil''' + CHAR(13)
+ 'SET @sql = ''PRINT '''''' +REPLACE(@quotedvar,'''''''','''''''''''') + '''''''''
+ CHAR(13) + 'PRINT @sql ' + CHAR(13) + 'EXEC sp_executesql @sql '

PRINT @topsql
PRINT '-------'

EXEC sp_executesql @topsql
aleksandr.milman
aleksandr.milman
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 22
What about something simpler:

declare @q nvarchar(50), @sql nvarchar(100)

set @q = '''o''''neil'''

set @sql = 'print ' + @q + ''
print @sql

EXEC sp_executesql @sql

___________________________________

print 'o''neil'
o'neil
webrunner
webrunner
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4245 Visits: 3887
Nemeaux (1/3/2013)
Although the overall technical correctness of this article is good there is a glaring error in the narrative. There is no such thing as a "single quote" mark. There is an apostrophe mark and there is a quotation mark. A single quote looks thusly " and a double quote looks this way "". What the article’s author refers to as a "single quote" is in reality an apostrophe mark ' and what is referred to as a "double quote" is actually a quotation mark.

I bring this up because the difference is really quite significant. Calling an apostrophe a "single quote" is, putting it simply, quite wrong. It would be like calling a “V” a single “W” and calling a “W” a “double W”.

When looking up "quotation marks" in the Oxford Online Dictionary, http://oxforddictionaries.com/words/punctuation, I see no punctuation mark labeled as "single quote". Nor is there a mention of a "double quote".

Yes, I'm tilting windmills. But one must try occasionally, mustn't one?

Thanks for the soapbox.


For your consideration:

http://english.stackexchange.com/questions/36046/apostrophe-vs-single-quote

Also here:
http://en.wikipedia.org/wiki/Quotation_mark

SQL uses what seems to be called typewriter quotation marks, or dumb or straight quotes. I think there is a semantic difference between apostrophes and single quotation marks. For example, many Penguin books use single quotation marks to set off dialogue. In that case, though, the "open quote" is in one direction and the "close quote" is in the inverted direction. So although you may be technically correct (I'm not yet sure that you are), it seems to be the case -- excepting the symmetrical straight or dumb quotes -- that while all apostrophes look like single (close) quotation marks, not all single quotation marks look like apostrophes. See also:
http://www.ergonis.com/products/tips/punctuation-apostrophes-quotation-marks.php

That typographical distinction doesn't exist in SQL, which uses a "dumb" quotation mark (for lack of a better term) rather than a "smart" one. So you may indeed be titling at windmills, although I happen to find those same windmills very interesting and am grateful that you contributed your comments to this discussion.

- webrunner

-------------------
"I love spending twice as long and working twice as hard to get half as much done!" – Nobody ever.
Ref.: http://www.adminarsenal.com/admin-arsenal-blog/powershell-how-to-write-your-first-powershell-script

"Operator! Give me the number for 911!" - Homer Simpson

"A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26884 Visits: 17557
At the very least the WWW consortium does not agree that there is no such thing.
‘ is left single quote
’ is right single quote

--EDIT--

Proof...I typed in the html escape sequence and they rendered on the page.
& lsquo;
& rsquo;

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Steven Willis
Steven Willis
SSC Eights!
SSC Eights! (859 reputation)SSC Eights! (859 reputation)SSC Eights! (859 reputation)SSC Eights! (859 reputation)SSC Eights! (859 reputation)SSC Eights! (859 reputation)SSC Eights! (859 reputation)SSC Eights! (859 reputation)

Group: General Forum Members
Points: 859 Visits: 1721
The standard ASCII character set is a holdover from the early days of teletype, band printers, computers and manual typewriters. (How many of you have ever seen a band printer? They were incredibly fast.)

If one wants to get nitpicky, typographers have always used the form of characters that was added to the standard ASCII to create the Extended Character set. Even in the days of lead type, most font sets--whether manual or automated linotype--included these typographical characters.

From the standard character set:

This is an apostrophe: ' (ASCII 39)
This is a quotation mark: " (ASCII 34)

From the extended characters set:

This is a left single quotation mark: ‘ (ASCII 145)
This is a right single quotation mark: ’ (ASCII 146)

This is a left double quotation mark: “ (ASCII 147)
This is a right double quotation mark: ” (ASCII 148)


ASCII 39 and ASCII 34--in typography--would be used to represent minutes and seconds when displaying latitude or longitude or as an abbreviation for feet and inches.

Oh, and since I used the double-hyphen above rather than a true em dash that is cause to differentiate there as well.

This is a hyphen: - (ASCII 45) used as a minus symbol, for compound words, or to break a word between lines.

This is an en dash: – (ASCII 150) used to represent a range such as 1952–1987.

This is an em dash: — (ASCII 151) used as a text separator. This symbol would properly be used in place of the double-hyphen—like this—rather than the double-hyphen typical of computers and typewriters.

And one final typographical note: the ellipsis is typically typed using three periods. But the proper method to display an ellipsis would be to use ASCII char 133: …


For anyone who really cares about proper typography The Chicago Manual of Style is the editor's Bible.

 
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search