user3235016
user3235016

Reputation: 317

Text search in SQL

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

Answers (2)

Marek
Marek

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

pid
pid

Reputation: 11597

You need this:

WHERE Lastname LIKE '%' + @Description + '%'

Where @Description is the substring to search for.

Upvotes: 2

Related Questions