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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Quote marks, apostrophes and strings

Author  Topic 

JacobPressures
Posting Yak Master

112 Posts

Posted - 2005-07-21 : 13:16:35
Query Analyzer seems to be able to tell the difference between the apostrophe and the opening and closing quotes. It doesn't give me an error when i check the syntax and it has everything in red that is supposed to be in red.

Should i trust this observation or should i change this somehow? I guess use double quotes.

Here is a sample of the code with apostrophes for possession. I placed questionable words in red.

-- EMPLOYEES TABLE ---------------------------------------------------

EXEC sp_addextendedproperty
'MS_Description', 'Primary key', 'User', 'dbo', 'table', 'Employees', 'column', 'EmpID'

EXEC sp_addextendedproperty
'MS_Description', 'Employee’s first name', 'User', 'dbo', 'table', 'Employees', 'column', 'FirstName'

EXEC sp_addextendedproperty
'MS_Description', 'Employee’s last name', 'User', 'dbo', 'table', 'Employees', 'column', 'LastName'

EXEC sp_addextendedproperty
'MS_Description', 'Employee’s badge number or number on check stub for salaried employees without badge numbers', 'User', 'dbo', 'table', 'Employees', 'column', 'BadgeNumber'

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-07-21 : 14:02:41
I imagine that sql will allow that because your apostrophe is not really a single quote:


select ascii('’')[funkyApostophe], ascii('''') [singleQuote]

funkyApostophe singleQuote
-------------- -----------
146 39


I don't like to use special characters for object names (or property values). I can't even type that apostrophe into a QA window with my normal keys. I'd go with more typical objectNames like:

EmployeeLastname or Employee_Lastname, etc...

if it was a real single quote you would need to double it up (two singles, not a double)

Be One with the Optimizer
TG
Go to Top of Page

JacobPressures
Posting Yak Master

112 Posts

Posted - 2005-07-21 : 14:30:53
It does seem to make a difference in Query Analyzer. If i use the funkyApostrophe as you call it, it doesn't recognize it as a string in quotes. If i change the funkyApostrophe to the regular or simple one (') then, it causes problems too.

I didn't know there was a difference and it should all be the same font. I didn't do anything special to create the funkApostrophe. I never had a problem with this in Visual Basic either.

What is the best practice? Get rid of it and use the simple quote ('). Then you say use double single quotes ''. Why not double quotes?

Thanks!
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-07-21 : 14:37:52
>>What is the best practice?

Don't use single quotes in object or property names. (I don't like spaces either).
Use single quotes to quote strings.
Use two single quotes as an "apostrophe" in a quoted string

Be One with the Optimizer
TG
Go to Top of Page

JacobPressures
Posting Yak Master

112 Posts

Posted - 2005-07-21 : 14:47:51
THANKS VERY MUCH!!! I WOULD HAVE NEVER FIGURED THAT ONE OUT AND WOULD HAVE BEEN LEAD TO THE WRONG CONCLUSION!!!!!!

Thanks Again! I knew nothinga about two single quotes.
Go to Top of Page
   

- Advertisement -