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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 searching strings for specific chars ?

Author  Topic 

pazzy11
Posting Yak Master

145 Posts

Posted - 2007-11-16 : 05:29:29
Hi if i wanna search a certain column for a specific character

so it could be '&' occuring anywhere in the string
can i use the like operator ?

so have something like
[CODE]
SELECT name from table
where name like '%&%'
[/CODE]

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-16 : 05:33:45
yes you can.

does that query not work for you?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

pazzy11
Posting Yak Master

145 Posts

Posted - 2007-11-16 : 05:36:09
yes it does but i was wondering did it cover everything ?
is '%&%' different from '%%&%%'

?
Go to Top of Page

pazzy11
Posting Yak Master

145 Posts

Posted - 2007-11-16 : 05:37:00
Another question , what about replacing said char with another one ?

can it be done with an UPDATE
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-16 : 05:40:32
yes you can . you have to use substring or replace function.
look them up in BOL = Books Online ? SQL Server Help

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

georgev
Posting Yak Master

122 Posts

Posted - 2007-11-16 : 08:09:57
Just a quick note to point out the other wildcard operator available in SQL Server.
The underscore (_)!
This can be used to represent a single character, whereas the percentage symbol (%) is used to denote any number of characters above and including zero.
[CODE]
SELECT *
FROM people
WHERE surname LIKE 'Smit_'
[/CODE]
Would return values such as "Smith"
Whereas
[CODE]
SELECT *
FROM people
WHERE surname LIKE 'Smit%'
[/CODE]
Could return "Smith", "Smithson", etc.

Hope this helps :)


George
<3Engaged!
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2007-11-19 : 07:58:13
quote:
Originally posted by pazzy11

Another question , what about replacing said char with another one ?

can it be done with an UPDATE



in result set (which is returned as a result of query processing it can be done as)
you can replace an exp/charracter by another one as

insert into testing values ('wwww@wew@soop@')
select replace([name],'@','#') from testing


Rahul Arora
MCA 07 Batch
NCCE Israna, Panipat
HRY, INDIA

######################
IMPOSSIBLE = I+M+POSSIBLE
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-11-19 : 10:24:09
quote:
Originally posted by arorarahul.0688

quote:
Originally posted by pazzy11

Another question , what about replacing said char with another one ?

can it be done with an UPDATE



in result set (which is returned as a result of query processing it can be done as)
you can replace an exp/charracter by another one as

insert into testing values ('wwww@wew@soop@')
select replace([name],'@','#') from testing


Rahul Arora
MCA 07 Batch
NCCE Israna, Panipat
HRY, INDIA

######################
IMPOSSIBLE = I+M+POSSIBLE




While that answer was already given, at least you did add at least something new by providing some sample code. So, still not an original or helpful answer, but I think that perhaps you did (finally) actually add some value to a thread, so good job! Keep it up!

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -