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

Stored Procedures with Passed Variables 1

Status
Not open for further replies.

ljevans

Technical User
Apr 4, 2001
53
US
I have a stored procedure that uses a "Like..." statement. It works fine if I hard code a value into it, but as soon as I pass a variable to it, it returns 0 records. It looks something like this
Code:
CREATE PROCEDURE getJobs
@job varchar(4)
AS 
SELECT item1, item2
FROM myTable
WHERE jobNumber Like '%@job%'

The data is stored as a varchar in the database and again, if I hard code a value into the statement, it returns 12 records.

Thanks
 

Change Select statement in the SP to this.

SELECT item1, item2
FROM myTable
WHERE jobNumber Like '%' + @job + '%'
Terry

;-) "When I hear somebody sigh, 'life is hard', I am always tempted to ask, 'compared to what'?" - Sydney Harris
 
Thanks!!! That worked like a charm.

I'm the same person who wrote the original post. I was just using a co-worker's computer at the time.

Thanks again for the help. Kevin
slanek@ssd.fsi.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top