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)
 Stored Procedures with Like

Author  Topic 

Nick
Posting Yak Master

155 Posts

Posted - 2001-11-26 : 10:28:28
Is it possible to write a stored procedure with a dynamic like clause, or will I have to do it using Dynamic SQL? For instance I want to do something like


Select a from b where c Like %d%

I am passing d to the stored procedure.

select a from b where c like '%@d%'

doesn't work because it is searching the the string '@d', and

select a from b where c like %@d% gives me all sorts of errors.. Am I going to have to use dynamic sql?

Thanks!

royv
Constraint Violating Yak Guru

455 Posts

Posted - 2001-11-26 : 10:36:06
Ya you can do this:

select a from b where c like '%' + @d + '%'

*************************
Just trying to get things done
Go to Top of Page

Nick
Posting Yak Master

155 Posts

Posted - 2001-11-26 : 10:39:46
Thank you, that worked great!

quote:

Ya you can do this:

select a from b where c like '%' + @d + '%'

*************************
Just trying to get things done



Go to Top of Page
   

- Advertisement -