Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Single Quote in Query 2

Status
Not open for further replies.

JohnMalv

Programmer
Jun 21, 2004
16
US
If I have a text field which I need to put some text and ascii data via a query, however that data contains one or more single quotes, is there a way to get that data in there without changing those quotes to a uniform "alternate" character? I tried \' already, and it still fails.
 
insert tbl select 'O''Hare'


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
If it wasn't obvious, what Nigel did was "escape" one single quote with another...

I.E. to get a litteral single quote, send two.

 
If your data is less than 256 characters (I believe) you may find the quotename function useful. Although, I see now in BOL that it returns Unicode. And also... weird... BOL says 258. I wonder if it's a typo.
 
Interesting, though, in this instance, I'm quite certain the field is longer than 256 characters. In fact there are instances where it can be 10k :).

Good advice though (though Unicode gives me nightmares.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top