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

LIKE in stored procedure

Status
Not open for further replies.

bboggessswcg

Programmer
Jun 6, 2003
34
0
0
US
Can anyone tell me how to use the LIKE command in a stored procedure? Below is my current stored procedure. I keep getting a syntax error. I need to use the like and %. Thanks in advance.

CREATE PROCEDURE myGetAllAttorneysSearch (@strCounty char(2), @strSearch char(20))

AS

SELECT ATTYMF.ATALPH

FROM ATTYMF

WHERE (ATTYMF.ATCTY = @strCounty AND (ATTYMF.ATALPH Like @strSearch %)

ORDER BY ATTYMF.ATALPH
GO
 
WHERE (ATTYMF.ATCTY = @strCounty AND (ATTYMF.ATALPH Like @strSearch +'%')

either that or this

WHERE (ATTYMF.ATCTY = @strCounty AND (ATTYMF.ATALPH Like '''' + @strSearch +'%''')
dlc
 
alter PROCEDURE myGetAllAttorneysSearch (@strCounty char(2), @strSearch char(20))
AS
declare @str varchar(1000)

set @str = 'SELECT ATTYMF.ATALPH FROM ATTYMF WHERE ATTYMF.ATCTY = '''
+@strCounty+''' AND ATTYMF.ATALPH Like '''
+left(@strSearch,len(@strSearch))+'%'' ORDER BY ATTYMF.ATALPH'

exec(@str)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top