SQL Server Forums
Profile | Register | 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
 Other SQL Server 2008 Topics
 retrieve data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Dhanushkodi
Starting Member

India
21 Posts

Posted - 04/30/2013 :  06:48:00  Show Profile  Reply with Quote
I have written the query with like

select type from table where type1 like '%sd%'

my data have "%" symbol. so how can i write the query to search the data.

if i write the query like this

select type from table where type1 like '%%%'

it wont working. it bring all the records. so help me out. thanks

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 04/30/2013 :  07:00:47  Show Profile  Reply with Quote
do you mean this?
select type from table where type1 like '%^%sd%' ESCAPE '^'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 04/30/2013 :  07:01:31  Show Profile  Reply with Quote
http://visakhm.blogspot.in/2013/01/wildcard-character-based-pattern-search.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Dhanushkodi
Starting Member

India
21 Posts

Posted - 05/03/2013 :  02:29:20  Show Profile  Reply with Quote
thank you visakh16. Now my query is working.

whats my doubt is, i have the following data in my table

FORM HE2. %

when i write the query as select * from wildChars where charss like '%^%%'. it's bring the following data

TEST!@#$%^&*
~!@#$%^&*

i have the data like "FORM HE2. %". it's not coming. it's contains "Space". please help me out to write the query.

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 05/03/2013 :  02:42:55  Show Profile  Reply with Quote
select * from wildChars where charss like '%^%%' ESCAPE '^'
If you want only data which contains % (percentage) symbol, you can use
select * from @tab where col like '%[%]%'
--
Chandu

Edited by - bandi on 05/03/2013 02:48:00
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 05/03/2013 :  03:13:34  Show Profile  Reply with Quote
quote:
Originally posted by Dhanushkodi

thank you visakh16. Now my query is working.

whats my doubt is, i have the following data in my table

FORM HE2. %

when i write the query as select * from wildChars where charss like '%^%%'. it's bring the following data

TEST!@#$%^&*
~!@#$%^&*

i have the data like "FORM HE2. %". it's not coming. it's contains "Space". please help me out to write the query.




its because you didnt specify ^ as a escape character using ESCAPE

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Dhanushkodi
Starting Member

India
21 Posts

Posted - 05/03/2013 :  03:37:47  Show Profile  Reply with Quote
thanks for your help. query is running perfectly. thanks a lot.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 05/03/2013 :  04:16:55  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000