dbTalk Databases Forums  

substring matching

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss substring matching in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
anoosh
 
Posts: n/a

Default substring matching - 07-19-2007 , 03:57 PM






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);


Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: substring matching - 07-19-2007 , 04:00 PM






anoosh (paytam (AT) gmail (DOT) com) writes:
Quote:
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, esquel (AT) sommarskog (DOT) 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


Reply With Quote
  #3  
Old   
Gert-Jan Strik
 
Posts: n/a

Default Re: substring matching - 07-19-2007 , 04:57 PM



Based on you narrative, the query you need is:

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

HTH,
Gert-Jan


anoosh wrote:
Quote:
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);

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.