Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / June 2008

Tip: Looking for answers? Try searching our database.

TSQL = LIKE search statement for a '%@%'

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Travis McGee - 29 Jun 2008 03:47 GMT
Does anybody know why searching for a string '@' with LIKE does not work
even when you use ESCAPE

Very strange......

Say the field has .....   I love my @*&!& friend
And I want to SELECT this row when I search for @ with LIKE
Select * from myTable where myField like '%@%'     does not work
Select * from myTable where myField like '%#@%'  escape '#'     does not
work either
Select * from myTable where myField like '%' + char(64) + '%'     does not
work either

What a pain in the something search + Why me

Any help???
Dan Guzman - 29 Jun 2008 04:06 GMT
> Say the field has .....   I love my @*&!& friend

CREATE TABLE dbo.myTable
(
   myField varchar(30)
)
INSERT INTO dbo.myTable(myField)
   VALUES ('I love my @*&!& friend')
GO

> And I want to SELECT this row when I search for @ with LIKE
> Select * from myTable where myField like '%@%'     does not work
> Select * from myTable where myField like '%#@%'  escape '#'     does not
> work either
> Select * from myTable where myField like '%' + char(64) + '%'     does not
> work either

I get the results below for all 3 queries:

myField
------------------------------
I love my @*&!& friend

There is nothing special about '@' here that comes to mind.  You might try
qualifying the table with the schema name.  Perhaps there are multiples
table with the same name but in different schema.

Signature

Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

> Does anybody know why searching for a string '@' with LIKE does not work
> even when you use ESCAPE
[quoted text clipped - 12 lines]
>
> Any help???
Michael Coles - 29 Jun 2008 07:46 GMT
See response in .datawarehouse.  Please don't multipost.

Signature

========
Michael Coles
"Pro SQL Server 2008 XML"
http://www.amazon.com/Pro-SQL-Server-2008-XML/dp/1590599837/

> Does anybody know why searching for a string '@' with LIKE does not work
> even when you use ESCAPE
[quoted text clipped - 12 lines]
>
> Any help???
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.