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
 General SQL Server Forums
 New to SQL Server Programming
 Quotation Mark in Where Clause

Author  Topic 

TPie9
Yak Posting Veteran

67 Posts

Posted - 2009-08-25 : 13:15:10
Below is my SQL code and corresponding error I receive:

select *
from Sales
where SalesRep = 'George O'Malley'

"Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'Malley'.
Msg 105, Level 15, State 1, Line 3
Unclosed quotation mark after the character string '''.

Any ideas how to accomplish my look up on the salesrep name that contains a quotation?

Thanks


YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-08-25 : 13:17:30
select *
from Sales
where SalesRep = 'George O''Malley'

Put two quotes by the O.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-25 : 13:17:48
You can mask a single quote by typing two single quotes.
where SalesRep = 'George O''Malley'

edit: typo corrected

No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-25 : 13:19:14



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

TPie9
Yak Posting Veteran

67 Posts

Posted - 2009-08-25 : 13:22:09
Thanks for the help because it accomplished what I needed.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-26 : 00:54:25
Also read http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -