469,904 Members | 1,956 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,904 developers. It's quick & easy.

substring matching

hi all
I want to write a sotred procedure which has a parameter,called
@name.The SQL statement must return all rows where this parameter is a
subatring of a special column called FirstName.This procdeure do the
same ,but return all rows where @name is the exact matching.what
should I do?
/*
This procedure return the exact matching
*/
CREATE PROCEDURE substring
@name varchar(50)
AS
SELECT *
FROM table1
WHERE (table1.firstName LIKE @name);

Jul 19 '07 #1
2 3381
anoosh (pa****@gmail.com) writes:
I want to write a sotred procedure which has a parameter,called
@name.The SQL statement must return all rows where this parameter is a
subatring of a special column called FirstName.This procdeure do the
same ,but return all rows where @name is the exact matching.what
should I do?
/*
This procedure return the exact matching
*/
CREATE PROCEDURE substring
@name varchar(50)
AS
SELECT *
FROM table1
WHERE (table1.firstName LIKE @name);
LIKE '%' + @name + '%'
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 19 '07 #2
Based on you narrative, the query you need is:

SELECT *
FROM table1
WHERE @name LIKE '%'+table1.firstName+'%'

HTH,
Gert-Jan
anoosh wrote:
>
hi all
I want to write a sotred procedure which has a parameter,called
@name.The SQL statement must return all rows where this parameter is a
subatring of a special column called FirstName.This procdeure do the
same ,but return all rows where @name is the exact matching.what
should I do?

/*
This procedure return the exact matching
*/
CREATE PROCEDURE substring
@name varchar(50)
AS
SELECT *
FROM table1
WHERE (table1.firstName LIKE @name);
Jul 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Tarun | last post: by
3 posts views Thread by colinhumber | last post: by
6 posts views Thread by joseph speigle | last post: by
7 posts views Thread by Kevin CH | last post: by
2 posts views Thread by Rob | last post: by
5 posts views Thread by Kris Kennaway | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.