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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to write a % in a string

Author  Topic 

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2009-03-11 : 16:19:31
I have a table called Product with a varchar field called Name. I want to select all records where Product contains % character anywhere in the string.

How to write this query.

Please help quickly.

Thanks,

Zee

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2009-03-11 : 16:30:26
Can someone help please....
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-03-11 : 16:51:41
why is there a name with % in the first place? is the field full-text indexed? if so use

SELECT * FROM Product AS t WHERE CONTAINS(Name, '%')

hope it is not too late, hope you passed the test
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-03-11 : 17:01:09
also

SELECT *
FROM Test AS t
WHERE FieldName LIKE ( '%!%') ESCAPE '!'; and using wildcard brackets []

following is best to find % anywhere in field
SELECT *
FROM Test AS t
WHERE FieldName LIKE '%!%%' ESCAPE '!';

Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2009-03-11 : 18:42:58
Thanks....
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-12 : 02:24:49
or

SELECT *
FROM Test AS t
WHERE FieldName LIKE ( '%[%]%')


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -