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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you insert text with double quotes into SQL server.

Status
Not open for further replies.

ironhide1975

Programmer
Joined
Feb 25, 2003
Messages
451
Location
US
Ok this one has been driving me crazy for years. I know that you can't insert a double quote into SQL server because thats what forms the query, and a singular quote you need to double up on two in order to put that into database.

But say you had actual text with one double quote

such as...

this is a double quote "

How do you get that into the text field in a database? Is there any way at all using ASP classic?

 
This may help you (at least from an ASP Classic standpoint): thread333-898275

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
In VB I tend to just concatanate the string around the quote character

Code:
qry  = "UPDATE mytable set name = 'this is a double quote " & Chr(34) & "' WHERE......."
 
Alternatively you could just
Code:
qry  = "UPDATE mytable set name = 'this is a double quote ""' WHERE......."
as VB.NET uses the same idea of doubling the quotes.
 
easy:
Code:
create table Quote (field1 text)


insert into Quote (Field1)
values ('this is a double quote "')

select * from Quote

BTW theend of the values line is quote (") and '

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
If someone enters a quote into say, a form text box. How do you grab that from the form and then convert/replace the characters to submit?

 
Code:
select replace('this " should not be in here','"','')

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top