Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a wild card field into a stored procedure

Status
Not open for further replies.

ericpsu32

Programmer
Sep 15, 2003
47
US
Here is my dilemma.

i would like to be able to pass a parameter into a stored procedure through access project and use that parameter as part of a wildcard search.

I can pass this parameter to the procedure, but the parameter is not being recognized as a wildcard.

Here is what I have been trying, but it isn't working because it is seeing the field as %whatever% and not '%whatever%'

FieldName Like '%' + @WildCard + '%'

I can't get it to recognize the quotes. Maybe i am going down teh wrong path entirely. Any help would be appreciated.

Thanks!
 
Denis...thanks for the quick reply.

I tried the code you sent and got the following...
%'tech'%

I would like my result to say
'%tech%'



 
I got the right result with this:
'''%'+ RTRIM(@WildCard) + '%'''

The problem is that the query still won't pull anything. I ran some simple queries to validate...

Select * from TABLE where FIELDNAME like '%tech%'
this works.

Select * from TABLE where FIELDNAME like @wildcard
This doesn't, even though @wildcard = '%tech%'
 
What is the value of @wildcard, can it be NULL?

What are the result of:
Code:
DECLARE @test varchar(8000)
SET @test = '%' + @wildcard + '%'
print @test

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
bothe of these should work

declare @wildcard varchar(50)
select @wildcard ='tech'


Select * from TABLE where FIELDNAME like '%' + @wildcard '%'


declare @wildcard varchar(50)
select @wildcard ='%tech%'


Select * from TABLE where FIELDNAME like @wildcard

Denis The SQL Menace
SQL blog:
Personal Blog:
 
If you got the result with RTRIM() then @WildCard is not varchar.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
OK... I got it with this. I found an error in another variable I was passing.

Thanks Denis...

Like '%'+ RTRIM(@WildCard) + '%'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top