Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 No Wildcards Characters
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 01/23/2013 :  01:43:48  Show Profile  Reply with Quote
Hi all,
I want to search for "[[% SQL Server %]]" pattern in a string value (Note, ] [ % are not wildcards).

I want an alternative LIKE for this without ESCAPE.

like '%?[?[?% SQL Server ?%?]?]%' ESCAPE '?'

I wrote this code, but that is not correct:

like '%[[][[][%] SQL Server [%][]][]]%'

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 01/23/2013 :  02:01:38  Show Profile  Reply with Quote
do you mean this?



SELECT *
FROM
(
SELECT '[[% SQL Server %]]' AS val UNION ALL
SELECT '[[%SQL Server]]' AS val UNION ALL
SELECT 'SQL Server' AS val UNION ALL
SELECT '[% SQL%]' 
)t
WHERE val LIKE '%[[[%] SQL Server [%]]%' 


output
-----------------------
val
-----------------------
[[% SQL Server %]]





------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Edited by - visakh16 on 01/23/2013 02:02:17
Go to Top of Page

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 01/23/2013 :  04:21:45  Show Profile  Reply with Quote
quote:
Originally posted by visakh16

do you mean this?



SELECT *
FROM
(
SELECT '[[% SQL Server %]]' AS val UNION ALL
SELECT '[[%SQL Server]]' AS val UNION ALL
SELECT 'SQL Server' AS val UNION ALL
SELECT '[% SQL%]' 
)t
WHERE val LIKE '%[[[%] SQL Server [%]]]%' 


output
-----------------------
val
-----------------------
[[% SQL Server %]]





------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Thank you, that's right. are there some good articls about such pattern matching?

my rewrite query: like '%?[?[?% SQL Server ?%]]%' escape '?'
Go to Top of Page

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 01/23/2013 :  06:51:54  Show Profile  Reply with Quote
Now how I should query for this by using square brackets ([]):
'[abcde]'

Is this correct?
like '[[]abcde]%'

or this?
like '$[abcde]%' escape '$'

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 01/23/2013 :  07:20:38  Show Profile  Reply with Quote
yep...that's correct

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 01/23/2013 :  07:25:26  Show Profile  Reply with Quote
your like is not correct
Execute this.
SELECT *
FROM
(
SELECT '[% SQL Server %]]' AS val UNION ALL
SELECT '[[%SQL Server%]]' AS val UNION ALL
SELECT '[% SQL Server %]' AS val UNION ALL
SELECT '[ SQL]'
)t
WHERE val like '%[[[%] SQL Server [%]]]%'

Edited by - sigmas on 01/23/2013 07:26:33
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000