Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««12345»»»

Single Quotation Marks in SQL Expand / Collapse
Author
Message
Posted Thursday, January 3, 2013 8:18 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 27, 2014 1:20 PM
Points: 9, Visits: 146
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.
Post #1402409
Posted Thursday, January 3, 2013 8:32 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 7:05 AM
Points: 3,467, Visits: 1,831
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 .


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
Post #1402414
Posted Thursday, January 3, 2013 8:44 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 27, 2014 1:20 PM
Points: 9, Visits: 146
Ah, if only we could now get BOL to see the light!

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

Dave
Post #1402418
Posted Thursday, January 3, 2013 8:58 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 10:52 AM
Points: 1,366, Visits: 1,729
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.
Post #1402426
Posted Thursday, January 3, 2013 9:10 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 7:05 AM
Points: 3,467, Visits: 1,831
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
Post #1402431
Posted Thursday, January 3, 2013 9:16 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 8:44 PM
Points: 121, Visits: 108
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
Post #1402436
Posted Thursday, January 3, 2013 12:34 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, March 18, 2014 12:27 PM
Points: 1, 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
Post #1402510
Posted Thursday, January 3, 2013 3:11 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 1:33 PM
Points: 2,414, Visits: 2,826
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


-------------------
"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
Post #1402586
Posted Thursday, January 3, 2013 3:18 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:10 AM
Points: 13,230, Visits: 12,709
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 Moden's 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)
Post #1402591
Posted Friday, January 4, 2013 9:58 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, September 29, 2013 1:24 AM
Points: 429, Visits: 1,721
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.

 
Post #1402971
« Prev Topic | Next Topic »

Add to briefcase «««12345»»»

Permissions Expand / Collapse