Solved

TSQL Query

Posted on 2014-12-21
1
140 Views
Last Modified: 2014-12-22
a question for a where statement in TSQL, what does escape '\\ mean ??

where A.PRODID NOT LIKE '%\-%' escape '\'  AND
0
Comment
Question by:AXISHK
1 Comment
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 40512420
There are some characters in the Sql pattern matching scenario that are special.

A percent sign for example is a wildcard that matches any string of 0 or more characters.

So how do you handle it when you need to search specifically for a '%' ?

This is where the escape keyword comes in.  You can tell the database that any time you see the escape character in the pattern followed by a wildcard character then that wildcats should be treated as a regular character instead.

The hyphen/dash character doesn't have any special meaning as far as I can recall so in your example it is looking for any string with a dash in it.  The percent signs are wild cards and since the backslash is the escape character it says that the dash should be treated exactly as a dash and not perform anything special.

Have a read of the books online article on using LIKE with ESCAPE.

Http://msdn.microsoft.com/en-us/library/ms179859.aspx
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question