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
 SQL Server Development (2000)
 Enter an apostrophe into database

Author  Topic 

jacky_chen84
Starting Member

1 Post

Posted - 2005-02-21 : 13:31:56
i am developing a system that allow user to enter any string into the database...it basically also allow user to enter a single quote if needed....
however, i found out that when my application convert a string that contain a single quote into sql statement for the sql server...the sql server treats it as the closing for the first part of the string...

eg...my sql statement

insert into Question(QuestionTitle)
values('Who's jacky mother?')

the apostrophe in the string is being treated as the closing for the string statement...how should i enter the apostrophe into SQL server?

Please help..thanks...

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-21 : 13:34:55
double the single quote:
insert into Question(QuestionTitle)
values('Who''s jacky mother?')

Go with the flow & have fun! Else fight the flow
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-21 : 14:57:23
set quoted_identifier off
select "Who's jacky mother?" as q into #t
select * from #t

rockmoose
Go to Top of Page

brendalisalowe
Constraint Violating Yak Guru

269 Posts

Posted - 2005-02-22 : 18:47:55
If you are using another language as the front end, I do something like this:

NewName = Replace(Tony's, "'", "`")

Brenda

If it weren't for you guys, where would I be?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-02-22 : 18:55:56
please, please use parameters for this stuff .... either a stored proc or if you insist on ad-hoc SQL you can still use parameters to pass in values to your SQL.

- Jeff
Go to Top of Page
   

- Advertisement -