Reputation: 317
I'm trying to make a stored procedure that would make it possible to search text. My goal is to make a stored procedure for search. I want the result when I EXEC it would get the list of Lastname so that I can search it. For example "James", then I want all James to be displayed using the stored proc.
Here is my code:
CREATE PROCEDURE spGetUser
@Description varchar(50)
AS
BEGIN
SELECT Lastname, Firstname FROM Users
WHERE Lastname LIKE '%'
ORDER BY Lastname
END
Upvotes: 1
Views: 69
Reputation: 3575
CREATE PROCEDURE spGetUser
@Description varchar(50)
AS
BEGIN
SELECT Lastname, Firstname FROM Users
WHERE Lastname LIKE '%' + @Description + '%'
ORDER BY Lastname
END
Upvotes: 0
Reputation: 11597
You need this:
WHERE Lastname LIKE '%' + @Description + '%'
Where @Description is the substring to search for.
Upvotes: 2