Escaping special characters in SQL Server 2008 - sql

I need your help on this: I am using SQL Server 2008 and have a stored procedure which is used to retrieve values from a table column.
Column of table contains description which could have anything including all special characters.
Is there any way I can escape all special characters ?
Thanks

try this
WHERE Description LIKE '%\ any text%'
here \ means ESCAPE

Related

Inserting a character into the middle of a string

I need to be able to insert a / in the middle of a string, so this 125674567 ends up like this 12/567/4567.
I am using SQL Server 2005.
Any help would be appreciated
Couple ways to do this...
You can use a combination of SUBSTRING and CONCAT or as a user mentioned in comments above, the STUFF statement.

how to write a word to a database that is between 2 Apostrophes?

I have a table in my database of type nvarchar(50);
I want to write to that specific column that string 'Tal' - Tal between 2 apostrophes.
When I'm trying to do so what is recorded in my DB is "Tal" - Tal between 2 quotation marks.
My database is an SQL database and so are my scripts.
How this can be solved?
The standard way to do what you want is this.
insert into mytable ( mycolumn ) values ('''Tal''');
The first and last ' are the start and end markers for the string. Each '' within these characters means '. Refer to page 89 of the SQL 92 specification at http://www.andrew.cmu.edu/user/shadow/sql/sql1992.txt
I think escaping is the key to your question. For SQL apostrophes are special characters, thus they have to be escaped by '' (two apostrophes). Have you checked that your scripts do not add the second apostrophe for you? Probably you have to add Tal without the apostrophes.
Escape % seems to be DB dependant. Oracles uses \%, others accespt [%] and some seem to have a keyword ESCAPE. You have read the documentation of your database, look for "escape characters".
Try inserting like this using the backslash \'Tal\'.

SQl Server insert Special characters

hi i m trying to insert 's in SQL sever i have search on solution to Replace 's to ''s then insert it is it valid solution or give me other solution
if you are going to insert values with single quote ', you have to escape it through single quote. So what you are doing is right.
You may see this article: SQL SERVER – How to Escape Single Quotes

Special character in varchar in SQL

I am inserting text from a file into a table, few of the lines have words like "you'll" or "don't". When I insert these lines as varchar in my table, I get an error saying - near "ll": syntax error. How do I overcome this?
Your single quote is being considered as the end of your string. Escape the quote that exists within your string to avoid this problem.
You need to escape your SQL statement. If you are using SQL Server, then you can use QUOTENAME to resolve this.
Use two apostrophes within apostrophe-quoted strings to insert the apostrophe:
insert into footable (foo) values('you''ll')
Thank you all for responses, since I was using sqlite3, there are inbuilt string formating functions available with the library, so I was able to use sqlite3_mprintf with %q instead of %s and it took care of single quotes.

Why are my accented characters breaking in SQL Server 2005?

When I update my database with this command:
UPDATE myTable SET Name = 'Hermann Dönnhoff' WHERE ID = 123;
SQL Server actually puts 'Hermann Do¨nnhoff' in the field instead. Instead of faithfully inserting the o-umlaut (char(246)), I'm getting two characters ( char(111) + char (168) ).
This happens for all characters that have accent marks, not just umlauts.
Has anybody seen this?
Thank you.
You need to use the nchar, nvarchar, or ntext datatypes for Unicode data.
The issue is that your code page does not directly support those characters.
Read up on collations for more information:
http://msdn.microsoft.com/en-us/library/aa214408%28SQL.80%29.aspx
http://msdn.microsoft.com/en-us/library/aa174903%28SQL.80%29.aspx