Hey everyone, I’m having some trouble with SQL Server 9. I’m trying to add text to a table, but it’s got a single quote in it. You know, like the apostrophe in “name’s”. I thought I knew how to deal with this. I tried doubling up the quote, like this:
insert into my_table values('hi, my name''s tim.');
But no luck. SQL Server just throws errors at me. What am I doing wrong here? Is there a special trick to escaping quotes in SQL Server that I’m missing? Any help would be awesome. Thanks!
hey silvia, have u tried the usual trick of doubling quotes in your insert?
i was wondering if u get a syntax error or a different message. maybe there’s another conflict?
i’d love to hear more about what error u see, so we can figure it out!
The approach you’ve taken with doubling the single quote is generally correct for SQL Server. However, the issue might lie elsewhere in your query or table structure. Have you verified the data types of your columns? Sometimes, unexpected errors occur when there’s a mismatch between the data you’re inserting and the column’s defined type. Additionally, ensure you’re not hitting any length constraints on the field. It might be worth double-checking your table definition and comparing it with the data you’re trying to insert. If the problem persists, examining the specific error message could provide more clues about what’s going wrong.