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
 Transact-SQL (2000)
 using a variable with like operator

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-08-23 : 10:00:37
Fabian writes "I want to pass a text parameter to a stored procedure. Then into the stored procedure code use that variable as a search condition with a like operator... How can i do it.

CREATE PROCEDURE Dummy
( @param char(40)

)
AS
BEGIN

select * from table where TextColum like [@param]

END"

Onamuji
Aged Yak Warrior

504 Posts

Posted - 2002-08-23 : 10:10:18
You need to use PATINDEX to search on TEXT data.

SELECT * FROM table WHERE PATINDEX(@param, TextColumn) > 0

...

Go to Top of Page

dsdeming

479 Posts

Posted - 2002-08-23 : 10:14:20
If you're talking abot a char or varchar column, you can try this:


declare @param char( 1 )
set @param = 't'
select * from tablename where columnname like '%' + @param + '%'

Go to Top of Page
   

- Advertisement -