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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT Store Procedure Help

Status
Not open for further replies.

EscapeUK

Programmer
Jul 7, 2000
438
GB
I have the following select statement which works fine

select * from mytable where refnumber1 like '%' and refnumber2 = 32 and refnumber3 = 48

However I have tried to convert this in to a stored procedure and I can't get values to be returned.

Here is the stored procedure:


CREATE PROCEDURE sp_Mysp
@Ref1 varchar(100),
@Ref2 varchar(100),
@Ref3 varchar(100)

AS
select *

from Mytable


Where Mytable.Refnumber1 LIKE @Ref1 And
Mytable.Refnumber2 LIKE @Ref2
Mytable.Refnumber3 LIKE @Ref2

Here are the ways I have tried to call it.

exec sp_mysp '%', '32', '48'

I have also tried

exec sp_mysp '%', 32, 48
 
Try this querry without the first option eg
exec sp_mysp 32, 48 and remove all the code that
was used as part of the Like statement. The query does
not look like a standard SQL query it looks like a JET DB
query.
 
Try this also...

CREATE PROC sp_mySp
@Ref1 varchar(100) = '%',
@Ref2 varchar(100) = '%',
@Ref3 varchar(100) = '%'
AS
SELECT * FROM myTable
WHERE RefNumber1 LIKE '%'+ @Ref1 + '%' AND
RefNumber2 LIKE '%'+ @Ref2 + '%' AND
RefNumber3 LIKE '%'+ @Ref3 + '%'

you will then execute the following as these:

EXEC sp_mySp '', 10, 20
or
EXEC sp_mySp 5, '', 20

in other words, you replace blank parameter with ''

Hope this helps.



Andel
maingel@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top