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 2000 Forums
 SQL Server Development (2000)
 search for '%' in a string

Author  Topic 

PGG123
Yak Posting Veteran

55 Posts

Posted - 2004-10-05 : 11:42:07
How do I do this? I am building a search query that would allow * as a wildcard, so I am replacing * with % in the query. But if the user decides to use % instead, I don't need to replace .

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-10-05 : 11:44:13
USE Charindex - look it up in BOL


Duane.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-10-05 : 12:10:27
[code]
USE Northwind
GO

SET NOCOUNT ON
GO

DECLARE @search varchar(255)
SET @search = '*Ale*'

SELECT *
FROM Products
WHERE ProductName LIKE REPLACE(@Search,'*','%')

SET @search = '%Lager%'

SELECT *
FROM Products
WHERE ProductName LIKE REPLACE(@Search,'*','%')
GO

SET NOCOUNT OFF
GO

[/code]


Brett

8-)
Go to Top of Page
   

- Advertisement -