SQL SERVER 2008 – How does one escape special characters when building SQL queries

The LIKE keyword allows for string searches. The ‘_’ wild card character is used to match exactly one character, ‘%’ is used to match zero or more occurrences of any characters. These characters can be escaped in SQL. Example:

SELECT name FROM emp WHERE id LIKE ‘%\_%’ ESCAPE ‘\’;

Use two quotes for every one displayed. Example:

SELECT ‘Franks”s Oracle site’ FROM DUAL;

SELECT ‘A ”quoted” word.’ FROM DUAL;

SELECT ‘A ””double quoted”” word.’ FROM DUAL;

Reference : Dilip Kumar Jena ( https://sqlexplore.wordpress.com )

Advertisements

One thought on “SQL SERVER 2008 – How does one escape special characters when building SQL queries

  1. hi . I have module which generate mail from database but sometimes special character occurs problem in mail. have you any idea to prevent or convert this special character in database mssql 2008 ?
    Thanks in advance for your solution.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s