Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below is the query where i am trying to update my table row but it's giving me some error In Sql Server.Can someone help me how to do this

What I have tried:

update table set col='It's' where col='It'
Posted
Updated 8-Jun-17 1:42am
Comments
Richard Deeming 8-Jun-17 11:21am    
If you're getting that error with hard-coded values, then Solution 1 is correct.

If you're getting the error with dynamic values provided by the user, it means you're building your queries incorrectly, leaving your code vulnerable to SQL Injection.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

1 solution

Yes, we can help you. However, for future reference, if you want help solving an error message, step 1 is to post the error message. There are 42,233,543 possible error messages so it helps to give the exact error and not make people guess.

In this case, the error is very simple. You have a single quote in the word "It's", therefore, it is breaking the string. The compiler thinks you want to update the col to be "It" and then you have "'s" and it has no idea what that means. You need to escape your apostrophe with another apostrophe.
SQL
UPDATE table SET col='It''s' WHERE col='It'


And the error message would have told you what was going on.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900